-
Consider the following C program:
#include
void mystery (int *ptra, int *ptrb){
int *temp;
temp = ptrb;
ptrb = ptra;
ptra = temp;
}
int main() {
int a=2016, b=0, c=4, d=42;
mystery (&a, &b);
if (a < c)
mystery (&c, &a);
mystery (&a, &d);
printf (“%d\n”, a);
}
The output of the program is_______.
-
- 2016
- 2011
- 216
- None of the above
Correct Option: A
As in C, parameters are passed by value - even if they are pointers. So, here the pointer values are exchanged within the function only (one can use * operator to exchange the values at the location of the pointers and this will affect the values in main). So, there will be no change in a, b, c, d. The output of the program is 2016.