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

Discussion

What will be the output of the program ?

#include <stdio.h>

int main()
{
    char *p;
    p="hello";
    printf("%s\n", *&*&p);
    return 0;
}

 

  • A.llo
  • B.hello
  • C.ello
  • D.h

Answer: B

Correct answer: hello

The operators * and & are inverses, so each adjacent pair cancels. Reading *&*&p from the right: &p gives the address of p, * takes us back to p, & takes the address again, and the final * returns to p.

The whole expression is therefore just p, and printf prints hello. Any even number of such pairs behaves the same way; the exercise exists to make the inverse relationship explicit.

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

Post your comment

Please log in or register to post a comment.