Consider the following function implemented in C:
void printxy(int x, int y) { int *ptr; x=0; ptr=&x; y=*ptr; *ptr=1; printf(“%d, %d”, x, y); }
The output of invoking printxy(1,1) is
at first in loop we are giving x=0 then ptr is pointing to X. so *ptr=0 now we copying the value of ptr to y ,so Y=0
x=0; //value of x = 0 ptr= &x; // ptr points to variable x y= *ptr; // Y contain value pointed by ptr i.e. x= 0;
now value of ptr is changed to 1. so the location of X itself got modified
*ptr=1;
as it is pointing to x so x will also be changed to 1 so 1,0 will be the value C is correct answer here
we got x= 1 and y= 1; void printxy(int x, int y) { int *ptr; //pointer is created which contain integer value. x=0; //value of x = 0 here. ptr= &x; // ptr point to variable which has 0 y= *ptr; // y contain value pointed by ptr i.e. x= 0; *ptr=1; // value pointer by ptr is now set to 1 i.e. x= 1; printf("%d,%d",x,y); // print x,y = x= 1 y=0
}
C is answer
1,0 is the answer
hope it might help.......
Gatecse