What is the output of this C program?

#include <stdio.h>
int main(void)
{
    int x = 5;
    int *p = &x;
    int **q = &p;
    **q = 40;
    printf("%d", x);
    return 0;
}
                        

Options

  • A. 5
  • B. Address of x
  • C. 40
  • D. More than one of the above
  • E. None of the above

Correct Answer (Detailed Explanation is Below)

C. 40

Detailed Explanation

Correct Answer: Option C

Explanation:
q points to p, and p points to x. Therefore, **q = 40 modifies the value of x through two levels of indirection. The program prints 40.