What is the output of this C code? #include void main() { int k=5; int *p=&k;…

2016

What is the output of this C code?

#include
void main()
{
int k=5;
int *p=&k;
int **m=&p;
printf("%d %d %d",k,*p,**m);
}
  1. A.

    5 5 5

  2. B.

    5 5 junk

  3. C.

    5 junk junk

  4. D.

    Compile time error

Attempted by 382 students.

Show answer & explanation

Correct answer: A

The code initializes k to 5, p as a pointer to k, and m as a pointer to p. Dereferencing *p gives the value of k (5). Dereferencing **m accesses the same memory location through two levels, also yielding 5. Thus, the output is '5 5 5'.

Explore the full course: Isro