The GATE Grind

GATE 2016 CS – Question 25

Programming and Data Structures · Programming in C · 1 mark · Numerical answer

Consider the following C program.

#include<stdio.h>
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 ________.

Practise this question in The GATE Grind →

Show answer and explanation

Correct answer: 2016

Explanation

`mystery` only swaps its own local copies of the two pointers, so it never changes the values that `a`, `b`, `c` and `d` hold. The value of `a` stays 2016, and since $2016 < 4$ is false the `if` does nothing either.