When I code like this and run, the console shows nothing:
#include<stdio.h>
int main()
{
int n2= 10;
int n1= 6;
int n0= 5;
int* p = &n1;
//printf("Address: %p\t%p\t%p\n", &n2, &n1, &n0);
*p=9;
p++;
*p=15;
p--;
p--;
*p=-3;
printf("n2=%d, n1=%d, n0=%d\n", n2, n1, n0);
getchar();
return 0;
}
But when I add
printf("Address: %p\t%p\t%p\n", &n2, &n1, &n0);
into my code, like this
#include <stdio.h>
int main()
{
int n2= 10;
int n1= 6;
int n0= 5;
int* p = &n1;
printf("Address: %p\t%p\t%p\n", &n2, &n1, &n0);
*p=9;
p++;
*p=15;
p--;
p--;
*p=-3;
printf("n2=%d, n1=%d, n0=%d\n", n2, n1, n0);
getchar();
return 0;
}
It runs in the way I expected (the result of n2 and n0 changed). I don't understand why, can anyone explain it for me?