C Programming - Pointers - Discussion

Discussion Forum : Pointers - Find Output of Program (Q.No. 17)
17.
What will be the output of the program ?
#include<stdio.h>

int main()
{
    char *p;
    p="hello";
    printf("%s\n", *&*&p);
    return 0;
}
llo
hello
ello
h
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
37 comments Page 2 of 4.

Mohd kamarshad said:   1 decade ago
Because & is reference operator and * is a dereference operator
so *(&p) converted into value at the address
this processes again...
and eventually we would get output as
--> hello

Suresh said:   1 decade ago
Hello. This is the platform for learning subject. Not for easy to remember shamini. Good try Mr. Mohd kaarshad.

Vishwa said:   1 decade ago
*&*&p = *(&(*(&p))) = *(&(*&p))=*(&p) = *&(p) = p

so it will print 'hello'

Ravichandra said:   1 decade ago
Thank you shamini & kaarshad both explain in their own way every one can understand.

Akash said:   1 decade ago
Very nice explanation Rajesh. Its conceptual.

Piyush said:   1 decade ago
Thanks shamini.

Deepak said:   1 decade ago
Thanks samini

Sarika said:   1 decade ago
Thanks samini.

Vishal said:   1 decade ago
Thanks shamini

Rishabh said:   1 decade ago
Thumb Rule for pointers:

'*' and '&' are like 'x' and '1/x', so will cancel each other whenever place together.

Hope this makes it simple to understand.


Post your comments here:

Your comments will be displayed after verification.