GATE Computer ScienceVery hardGATE CS (PYQ pattern)
int a[] = {10, 20, 30, 40}; int *p[] = {a, a + 1, a + 2, a + 3}; int **pp = p; int t1 = **pp++; int t2 = *++*pp; int t3 = ++**++pp; printf("%d %d %d %td", t1, t2, t3, pp - p); What is printed?
- A. 10 20 31 2
- B. 10 30 31 2
- C. 10 30 30 2
- D. 20 30 31 1
Correct answer: B. 10 30 31 2
pp++ yields p[0], so t1 = 10 and pp -> p[1]. *++*pp bumps p[1] itself to &a[2], so t2 = 30. ++pp makes pp -> p[2] = &a[2]; ++**pp makes a[2] = 31. pp - p = 2.
Practise more Programming and Data Structures (GATE) questionsProgramming and Data Structures (GATE): notes and key points
More Programming and Data Structures (GATE) questions
- Assume char is 1 byte, int is 4 bytes with 4-byte alignment, double is 8 bytes with 8-byte alignment, and the compiler inserts only the…
- int cnt = 0; int f(int n) { cnt++; if (n <= 1) return 1; if (n == 2) return f(1) + 1; return f(n - 1) + f(n - 2) + f(n - 3); } After f(6)…
- int g(int n) { static int s = 0; s += n; if (n > 0) { g(n - 1); s += n; } return s; } int main() { int x = g(3); int y = g(2); printf("%d…
- void p(int n) { if (n == 0) return; printf("%d ", n); p(n - 1); printf("%d ", n 10); if (n % 2 == 0 && n > 2) p(n - 2); } How many numbers…
- void f(int x, int y, int z) { x = y + z; y = x - z; z = x; } int main() { int a = 1, b = 2, c = 3; f(&a, &b, c); f(&b, &a, c); f(&a, &a…
- int h(int n) { return n == 0 ? 0 : 2 h(n / 10) + n % 10; } What is h(2593)?