Machine-translated by Google. Questions are authored in English.
Top

Discussion

What is the output of this C code?
 

void main()
{
int k = 5;
int *p = &k;
int **m = &p;
printf("%d%d%d\n", k, *p, **p);
}

 

  • A.5  5  5
  • B.5  5 junk value
  • C.5 junk value
  • D.Compile time error

Answer: D

Correct answer: Compile time error

The last argument is **p, but p is an int *, so *p is an int and applying * to an integer is not allowed. The number of dereferences must match the number of levels the pointer actually has. Writing **m instead, as in the previous question, is the correct form and gives 5.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.