In the given program, in mystery function only addresses are swapped not the values. Values remain same as in the main function. Pointer swapping is local to the mystery function here.
In C language, parameters are passed by value even if they are pointer. So, there will be no change in the value of a, b, c and d.
Code Explanation:
int main () {
int a = 2016, b = 0, c = 4, d = 42; // a= 2016, b= 0
mystery (&a, &b); // call void mysery (int *ptra, int *ptrb)
if (a < c)
mystery (&c, &a);
mystery (&a, &d);
printf (‘’%d\n’’, a);
}
void mysery (int *ptra, int *ptrb) // ptra = 2016, ptrb =0 during first call
{
int *temp;
temp = ptrb;
ptrb = ptra;
ptra = temp; // ptra = 0, ptrb = 2016,
}
But after this mystery(&a, &b); popped out of stack and all the pointers lost and all values wil remain same as original.
printf (‘’%d\n’’, a); // it will print the value of a i.e. 2016.