What will be the output of the program ?
#include <stdio.h>
int main()
{
char *p;
p="hello";
printf("%s\n", *&*&p);
return 0;
}
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.
Please log in or register to report this question.