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

Discussion

What is the output of this C code?

void main()
{
int a[3] = {1, 2, 3};
int *p = a;
int *r = &p;
printf("%d", (**r));
}

 

  • A.1
  • B.Compile time error
  • C.Address of a
  • D.Junk value

Answer: B

Correct answer: Compile time error

p is an int *, so &p has type int **, and initialising an int * from it is a constraint violation - the levels of indirection do not match. The declaration should read int **r = &p;, which is exactly what the following question does. Some compilers downgrade this to a warning, but it is an error in standard C.

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

Post your comment

Please log in or register to post a comment.