DIGIT-ARC read-only archive · snapshot: July 23, 2026

what is *&???

10 posts · originally from https://geek.digit.in/community/threads/what-is.146254/

bijay_ps
bijay_ps Original post #1
Sep 10, 2011 at 12:06 AM
I got this question from a study material for GATE exam. The code is as follows:
Code:
#include<stdio.h>
void main()
{

 char *p;

 p="Hello";

 printf("%c\n",*&*p);

}
someone please explain me what is this *&*p and what and how it does??
Neuron
Neuron #2
Sep 10, 2011 at 12:39 AM
It's actually a tricky question from 'pointers' in c.
char *p is a character type pointer.It means the the content at the address p, is of type char.
& is, well you can say, is an inverse operator of *.means &* just cancel each other of.
So 'printf("%c\n",*&*p)' is just 'printf("%c\n",*p)'
Since *p is a char and not a group of characters, p="Hello" will only store 'H' at the address p.
p=>an address *p=>content at that address.

This is basic stuff .You should have figured it out on your own.
nims11
nims11 #3
Sep 10, 2011 at 12:44 AM
for convenience,
consider *&*p as *(&(*p))

p has the address to 'H'. it is first dereferenced using *, then again referenced using & and then again dereferenced using * to 'H'.

in your case, &(*p)=p.
Liverpool_fan
Sep 10, 2011 at 8:13 AM
GATE exam has void main() in its question? Or is it just with the study material? :|

Since *p is a char and not a group of characters, p="Hello" will only store 'H' at the address p.
Actually "Hello" is a string literal, and p = "Hello" will point the address of p to the "read only" memory location where "Hello" is stored.
Clarification - *stackoverflow.com/questions/5342511/c-null-pointer-with-string-literals
Faun
Faun #5
Sep 10, 2011 at 10:27 AM
So the answer is H ?

Amidoinrite ?
Neuron
Neuron #6
Sep 10, 2011 at 1:05 PM
^^No
Just kidding!:mrgreen:

Actually "Hello" is a string literal, and p = "Hello" will point the address of p to the "read only" memory location where "Hello" is stored.
Clarification - c++ - C null pointer with string literals - Stack Overflow

True.I get it. printf("%s",p) will print the entire string literal.
Liverpool_fan
Sep 10, 2011 at 1:06 PM
The answer is Warning: main should always return int.,

P.S.: postlikethisoutsideprogrammingoss
A
Sep 10, 2011 at 9:41 PM
^^^
i think you are using g++.
Just change void to int and add return 0 at the end.
Actually it is always good to return integer through main, to know if program is exited properly!!
Liverpool_fan
Sep 10, 2011 at 9:48 PM
^ er... I didn't even bother to compile it.
Anyway, it's not only it's good to use int with main, using anything else apart from int with main violates the ANSI standards, and that's the end of that.
Clarification - void main(void) - the Wrong Thing
bijay_ps
bijay_ps #10
Sep 12, 2011 at 12:16 AM
actually in the question it was just main() only. And the answer is H. And thnx for all your replies I understood the concept

This is basic stuff .You should have figured it out on your own.
Yes Neuron I should have tried it by myself but I was a bit impatience.... and thnx for your explanation buddy