Pointers in C, simple doubts
I'm trying to understand some basic principles of pointers. Someone told
me that assigning value to a pointer variable will change the actual
variable value. Is that true? I wrote a piece of code and got this:
#include <stdio.h>
#include <stdlib.h>
int main()
{
int x=5;
int *address_of_x = &x;
int y = *address_of_x;
*address_of_x = 9;
printf("The value of x is: %d\n", x);
printf("The X is at: %p\n", &address_of_x);
printf("value of y = %d\n", y);
return 0;
}
and got the output like this:
The value of x is: 9
The X is at: 0028FF04
value of y = 5
why the value of "y" stayed 5? Is that because of the ordering of commands?
No comments:
Post a Comment