Question:

What is the output of the following piece of C code? int a[2] = { 13, 31 }; int *p = a; printf("%d, %d", *p, *p++);

Show Hint

Understand the behavior of the post-increment operator, which increments the pointer after the value is accessed.
Updated On: May 3, 2025
  • 13, 31
  • 31, 13
  • 13, 14
  • 13, 13
Hide Solution
collegedunia
Verified By Collegedunia

The Correct Option is C

Solution and Explanation

The expression \( p++ \) involves the post-increment operator. It first prints the value of \( p \), which is 13, and then increments the pointer \( p \). After the increment, the pointer points to the second element of the array (31). The next dereference of \( p \) prints 14, since the pointer now points to 31 and then increments again.
Thus, the output is \( 13, 14 \).
Was this answer helpful?
0
0

Top Questions on Programming in C

View More Questions