Skip to content
Related Articles

Related Articles

Improve Article
Output of the program | Dereference, Reference, Dereference, Reference….
  • Difficulty Level : Easy
  • Last Updated : 09 Aug, 2018

Predict the output of below program




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

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




#include<stdio.h>
int main()
{
 char *ptr = "geeksforgeeks";
 printf("%s\n", *&*&ptr);
   
 getchar();
 return 0;
}
Want to learn from the best curated videos and practice problems, check out the C Foundation Course for Basic to Advanced C.
My Personal Notes arrow_drop_up
Recommended Articles
Page :