In my C programing class I was given an assignment to create an array stack only using pointers to keep track of and change the values, however the use of pointer arithmetic was not covered completely. The course book doesn't explain it either. I'm trying to understand how to do this.
The code I'm trying to learn with is:
Code:
//test file
#include <stdio.h>
int stack[] = {11,22,33,44};
int *top = stack;
int main()
{
printf("%d\n",*top);//should print 11
*top = *(top + 1);
printf("%d\n",*top);//should print 22
*top = *(top + 1);
printf("%d\n",*top);//should print 33
*top = *(top - 1);
printf("%d\n",*top);//should print 22
scanf("%c");//keeps window open
return 0;
}
and the output I get is:
Im having a little bit of trouble understanding this...