#include #define Stack_Max 8 int* TopOfStack; int* CurrentStackPosition; int Stack[Stack_Max]; void PushStack(int); void PopStack(); int main() { TopOfStack = Stack; CurrentStackPosition = Stack; for(int i = 0; i < Stack_Max; i++) { PushStack(i); } for(int i = 0; i < Stack_Max; i++) { PopStack(); } return 0; } void PushStack(int pValue) { if(CurrentStackPosition != (TopOfStack + Stack_Max)) { printf("Added %d to the stack at position %d (%d)\n", pValue, CurrentStackPosition, pValue); *CurrentStackPosition = pValue; ++CurrentStackPosition; } else { printf("Stack overflow will occur beyond this point. Will not add %d to stack\n", pValue); } } void PopStack() { if(CurrentStackPosition != TopOfStack) { --CurrentStackPosition; printf("%d\n", *CurrentStackPosition); } else { printf("Top of stack reached!"); return; } }