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

Discussion

What is the output of the below code snippet?

#include <stdio.h>

main() 
{
   unsigned x = 5, y=&x, *p = y+0; 

   printf("%u",*p);
}

 

  • A.Address of x
  • B.Address of y
  • C.Address of p
  • D.5

Answer: D

Correct answer: 5

y holds the address of x, and p is set to that same address, so *p is x itself - 5. (The code stores an address in an unsigned int, which is poor practice and provokes warnings; it happens to work only where a pointer and an unsigned int are the same width.)

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

Post your comment

Please log in or register to post a comment.