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.

Abhay said:   1 decade ago
@Deepu is right and people who saying p="hello" are wrong because p is a pointer so *p=h; since it is string it will print hello.
(1)

Jogamohan Medak said:   1 decade ago
Ans:[B] Because:

Given p="hello"

p=*(&p)=*&p

p=*&p=*(&(*&p))

p=*&*&p=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'

Atiq shaiklh said:   9 years ago
if & and * both of them come together they will cancel out and remain is *p and it will print Hello.

Venky said:   9 years ago
The reference operator and the dereference operator gets cancelled. And it will print hello.

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

User said:   9 years ago
Because * is called dereference and & is called reference so * is cancel with &.

Manasa said:   1 decade ago
Thanks shamini I don't know how to do it your answer is easy to remember.

Sharanu hugar said:   1 decade ago
Thanks shamini....but u have to use printf instead of scanf..


Post your comments here:

Your comments will be displayed after verification.