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?
- A. 31
- B. 13
- C. 12
- 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
- A recursive function is written as int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }. What is gcd(1071, 462)?
- Starting at n = 27, the loop while (n != 1) { n = (n % 2) ? 3 n + 1 : n / 2; steps++; } runs with int n. What is steps at the end?
- Using square-and-multiply on int values with a reduction modulo 1000 after each multiplication, what is 3^13 mod 1000?
- How many 6-bit masks have exactly two 1 bits and have bit 0 cleared?
- The binary-reflected Gray code of i is g(i) = i ^ (i >> 1). What is g(4)?
- What is popcount(0xFFFF0000 ^ 0x0F0F0F0F)?