Nishant Kumar Nishant Kumar - 3 months ago 9
C Question

my c code giving same output for every input of p?

#include <stdio.h>

int main(int argc, char **argv) {
// your code goes here
char *p;
p = "hello";

printf("%s",*&*&p);
return 0;
}


It give same output for
p
,
*&p
,
*&*&p
. how is this possible?

Answer

* means give whatever is at this location in memory.
& gives the memory address of this object.

Therefore:
p is the string
*&p means give me whatever is at the location of p
*&*&p means give me whatever is at the location that is at the location of p

So all of those just give you p.