+ 7

What is happening in this code?

Output of below code is h , plz explain how ? What happens when we use operator * or & more than once in same line ? int main() { char *ptr = "helloword"; printf("%c\\n", *&*&*ptr); return 0; }

29th Jan 2021, 6:08 AM
Hrutik Bhalerao
Hrutik Bhalerao - avatar
4 Respuestas
+ 4
Here your decleared *ptr pointer which type is char type and u storing helloworld in printf statement u use %c after that \\n Slash work as separatator so if u will write two slash it single Slash will be print then *ptr will point first char &ptr will print address then *&ptr again pointing first char then & address then * for value. So that *&*&*ptr will point value which is first char h So output will be h \n
29th Jan 2021, 6:36 AM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 5
Thank you Syrah Algena . Now I get it . The extra slash is by mistake , by the way \n is unusable there . So, in simple (*,&) these operators cancel out effect of each other when used one after another?
29th Jan 2021, 6:47 AM
Hrutik Bhalerao
Hrutik Bhalerao - avatar
29th Jan 2021, 6:48 AM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 1
Pointr 0 +1 +2 +3 +4 +5 +6 +7 +8 Vaue. h e l l o w o r d Pointr its a address of cell in memory Value its a char in cell.
30th Jan 2021, 6:43 AM
SERG Starkov
SERG Starkov - avatar