Created
November 29, 2022 01:53
-
-
Save eduardopoleo/1d5240aae4078a3744c049bdb33cdd74 to your computer and use it in GitHub Desktop.
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> | |
#define MAX_DEPTH 100 | |
int top = -1; | |
int stack[MAX_DEPTH]; | |
char pop(); | |
char pop() { | |
int value = stack[top]; | |
top -= 1; | |
printf("inside pop! top %d, value: %d\n", top, value); | |
return value; | |
} | |
void push(int c); | |
void push(int c) { | |
stack[++top] = c; | |
printf("inside pushed! top %d, value: %d\n", top, stack[top]); | |
} | |
int value2; | |
int main() { | |
push(2); | |
push(400); | |
value2 = pop(); | |
printf("pop! %d\n", value2); | |
value2 = pop(); | |
printf("pop! %d\n", value2); | |
return 0; | |
} | |
/* | |
inside pushed! top 0, value: 2 | |
inside pushed! top 1, value: 400 | |
inside pop! top 0, value: 400 | |
pop! -112 <<--- WTF? | |
inside pop! top -1, value: 2 | |
pop! 2 | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment