Output of the program | Dereference, Reference, Dereference, Reference….

Predict the output of below program

filter_none

edit
close

play_arrow

link
brightness_4
code

#include<stdio.h>
int main()
{
 char *ptr = "geeksforgeeks";
 printf("%c\n", *&*&*ptr);
   
 getchar();
 return 0;
}

chevron_right


Output: g

Explanation: The operator * is used for dereferencing and the operator & is used to get the address. These operators cancel effect of each other when used one after another. We can apply them alternatively any no. of times. For example *ptr gives us g, &*ptr gives address of g, *&*ptr again g, &*&*ptr address of g, and finally *&*&*ptr gives ‘g’

Now try below

filter_none

edit
close

play_arrow

link
brightness_4
code

#include<stdio.h>
int main()
{
 char *ptr = "geeksforgeeks";
 printf("%s\n", *&*&ptr);
   
 getchar();
 return 0;
}

chevron_right




My Personal Notes arrow_drop_up

Improved By : MOHAKGOEL



Article Tags :
Practice Tags :


1


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.