-
-
Save ibeauregard/15e7bd77c5c9849a81a3dcc6280d3f47 to your computer and use it in GitHub Desktop.
Separate declarations and definitions with forward declarations
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
typedef struct int_node IntNode; // Forward declaration for struct int_node | |
typedef struct int_stack { | |
IntNode* top; | |
} IntStack; | |
struct int_node { | |
int value; | |
struct int_node* next; | |
}; | |
static void push_to_stack(IntStack* stack, int value); // Forward declaration | |
static int pop_stack(IntStack* stack); // Forward declaration | |
int main() | |
{ | |
IntStack* stack = malloc(sizeof (IntStack)); | |
stack->top = NULL; | |
for (int i = 5; i > 0; i--) { | |
push_to_stack(stack, i); | |
} | |
printf("At the top of the stack is `%d`\n\n", stack->top->value); | |
while (stack->top) { | |
printf("`%d` was popped from the stack\n", pop_stack(stack)); | |
} | |
free(stack); stack = NULL; | |
return 0; | |
} | |
void push_to_stack(IntStack* stack, int value) | |
{ | |
// Implementation... | |
} | |
int pop_stack(IntStack* stack) | |
{ | |
// Implementation... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment