ProgrammingHardGATE CS · Campus placements

int a[] = {1, 2}; int b[] = {3, 4}; int *x = a, *y = b; void swap(int **p, int **q) { int *t = *p; *p = *q; *q = t; } After swap(&x, &y) runs, what does printf("%d", *x * 10 + *y) print?

  1. A. 31
  2. B. 13
  3. C. 12
  4. D. 34

Correct answer: A. 31

The swap exchanges the two pointers, not the arrays, so x now points at b and y at a. *x is 3 and *y is 1, giving 31.

More C Programming questions

Exams that ask this topic