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;
}
Discussion:
37 comments Page 4 of 4.
Sharanu hugar said:
1 decade ago
Thanks shamini....but u have to use printf instead of scanf..
Sharanu hugar said:
1 decade ago
Thanks shamini....but u have to use printf instead of scanf..
Raj said:
1 decade ago
Good explanation rajesh.
Rajesh said:
1 decade ago
see
p=&(*p);
*p=*&(*p);
so it will print *p;
actually *p is value and &(*p) is adress of value of p i.e nothing but p itself (base adress).
so now *(&*p) is nothing but he is asking about the value of p
thats it
p=&(*p);
*p=*&(*p);
so it will print *p;
actually *p is value and &(*p) is adress of value of p i.e nothing but p itself (base adress).
so now *(&*p) is nothing but he is asking about the value of p
thats it
Gopika said:
1 decade ago
thanks shamini
Shamini said:
2 decades ago
Easy way to remember * and &..
When char *p="hello";
scanf("%s",*&p);
It will print hello only.. becoz * and & will get cancel and so in this
problem *& and *& will get cancel and print hello only.
When char *p="hello";
scanf("%s",*&p);
It will print hello only.. becoz * and & will get cancel and so in this
problem *& and *& will get cancel and print hello only.
Ravi said:
2 decades ago
Please explain this.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers