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 1 of 4.
Sakshi Munya said:
6 years ago
Very nice explanation. Thanks @Deepu.
Amar dengale said:
7 years ago
Hi, I am not getting this. Explain the question.
Srinika said:
7 years ago
Hello, can anyone explain me this?
Char *p.
Here *p is a pointer so it can store the only address of a character. But we are assigning it a string? How is that possible?
Char *p.
Here *p is a pointer so it can store the only address of a character. But we are assigning it a string? How is that possible?
(1)
Amit said:
8 years ago
#include<stdio.h>
int main()
{
char *p;
p="hello";
printf("%s\n",*p);//it is not working why?
//*p means value at address
//pointer variable store the address of another variable but here hello is what.
return 0;
}
int main()
{
char *p;
p="hello";
printf("%s\n",*p);//it is not working why?
//*p means value at address
//pointer variable store the address of another variable but here hello is what.
return 0;
}
Rajan said:
8 years ago
*p will give run time error, p will print hello.
Irisident said:
8 years ago
Thanks @Shamini.
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.
Wasi said:
9 years ago
Whenever * and & comes we just need to simply cancel.
for e.g
p=10;
q=&p;
t=*&p--->means t=p
And if we print *&p it will print 10.
for e.g
p=10;
q=&p;
t=*&p--->means t=p
And if we print *&p it will print 10.
(1)
Abhijeet said:
9 years ago
Very helpful, Thanks everyone.
Venky said:
9 years ago
The reference operator and the dereference operator gets cancelled. And it will print hello.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers