For example, this code below I just recently started working with pointers.
#include<stdio.h>
int main(){
int x = 3;
int y = 7;
int *ip; //creating int pointer ip
ip = &x; // ip storing the address of x
printf("Address of x: %d\n", ip);
*ip = 5;
printf("Address of x: %d\n", ip);
ip = &y; // ip also storing the address of y
printf("Address of y: %d\n", ip);
*ip += 11;
x += *ip;
printf("%d\n", x); // value is 23
printf("%d\n", y); // value is 18
printf("%d\n", *ip); // value is 18
}
The code runs fine I wanna know why. I was thinking after the pointer start holding the address of the variable y
the changes made using the pointer when it was pointing to x
should be reverted since it no longer holds the address.