Home » Programming & Data Structure » Programming and data structure miscellaneous » Question

Programming and data structure miscellaneous

Programming & Data Structure

  1. 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_______.
    1. 2016
    2. 2011
    3. 216
    4. 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.



Your comments will be displayed only after manual approval.