In: Computer Science
Explain an example in which a variable has two different addresses at different places in a program.
#include<stdio.h>
int main(){
int x=2,y;
y=3;
int *ptr; //Here we use *ptr a pointer variable to show the different addresses in a program
ptr = &x; // Here we are taking x address to the pointer variable *ptr
printf("%x\n",ptr); //Here we are printing the *ptr means pointer variable address
ptr = &y; // Here we are taking y address to the pointer variable *ptr
printf("%x\n",ptr); //Here we are printing the *ptr means pointer variable address
/*Here we have used a one single pointer variable *ptr in two different places to get two different addresses in a program. so, It is possible to get two different addresses in two different places in a program. */
}
Thank You...!