Question:

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\n", x, z[0], z[1]);
return 0;
}

Show Hint

In pointer arithmetic, `&z[0] + 1` moves the pointer to the next element in the array. The expression `(&z[0] + 1)` accesses the value of the next element.
Updated On: Jan 11, 2026
  • 1, 10, 11
  • 1, 10, 14
  • 10, 14, 11
  • 10, 10, 14
Hide Solution
collegedunia
Verified By Collegedunia

The Correct Option is D

Solution and Explanation

1. Initialization: - `x` is initialized to 1. - `z[2]` is initialized to `{10, 11}`. So `z[0] = 10` and `z[1] = 11`. - Pointer `p` is initialized to `NULL`, but it is reassigned to point to `x` and then to point to `z[1]`. 2. First assignment (`p = 10`): The pointer `p` is pointing to `x`, so the value of `x` is changed to 10. 3. Second assignment (`(&z[0] + 1) += 3`): The expression `&z[0] + 1` gives the address of `z[1]` (i.e., it points to `z[1]`), and then the value at this address is increased by 3. So, `z[1]` becomes `14`. 4. Final values: - `x = 10` - `z[0] = 10` (unchanged) - `z[1] = 14` (after modification) Thus, the output printed is `10, 10, 14`. Therefore, the correct answer is (D).
Final Answer: (D)
Was this answer helpful?
0
0

Top Questions on Programming in C

View More Questions