ProgrammingVery hardProduct company OA · GATE CS
What is printed?
What is printed?
int a = 1, b = 2, c = 3;
int *arr[] = {&a, &b, &c};
int **pp = arr + 1;
**pp += 10;
*pp[1] += 20;
printf("%d %d %d", a, b, c);- A. 1 12 23
- B. 1 32 3
- C. 21 12 3
- D. 1 12 3
Correct answer: A. 1 12 23
pp points at arr[1], so **pp is b, which becomes 12. Subscripting binds tighter than *, so *pp[1] is *(pp[1]) = *arr[2], which is c, now 23. Reading it as (*pp)[1] would step past b inside no array, which is not what the code says.
More C Programming questions
- Assume 32-bit unsigned int. What is printed? c unsigned mask(int lo, int hi) { return ((1u << (hi - lo + 1)) - 1) << lo; } int main(void)…
- What is printed? c int f(unsigned x) { int c = 0; while (x & (x >> 1)) { x &= x >> 1; c++; } return c + (x != 0); } int main(void) {…
- What is printed? c char d[6] = "zzzzz"; strncpy(d, "abc", 2); printf("%s", d);
- Assume ASCII. What is printed? c char s[] = "xyzAB"; for (char p = s; p; p++) if (p >= 'a' && p <= 'z') p = 'a' + (p - 'a' + 3) % 26…
- What is printed? c int up(int a, int b) { return (a + b - 1) / b; } int main(void) { printf("%d %d %d", up(10, 3), up(9, 3), up(0, 3)); }
- What is printed? c int t = 0; for (unsigned i = 0; i < 16; i++) for (unsigned x = i; x; x &= x - 1) t++; printf("%d", t);