StreakPeaked· Practice

ExamsGATETechnical

What is printed by the following ANSI C program? #include<stdio.h> int main(int argc, char *argv[]) { int x = 1, z[2] = {10, 11}; int *p = NULL; p = &x; *p = 10; p = &z[1]; *(&z[0] + 1) += 3; printf("%d, %d, %d ", x, z[0], z[1]); return 0; }

  1. 1, 10, 11
  2. 1, 10, 14
  3. 10, 14, 11
  4. 10, 10, 14

Correct answer: 10, 10, 14

Solution

The program modifies the value of 'x' through the pointer 'p', setting it to 10. It then updates 'z[1]' by adding 3 to 'z[0]', which is 10, resulting in 'z[1]' becoming 14. Therefore, the final output is '10, 10, 14'.

Related GATE Technical questions

⚔️ Practice GATE Technical free + battle 1v1 →