Open In App
Related Articles

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

Improve Article
Improve
Save Article
Save
Like Article
Like

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;
}


Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 09 Aug, 2018
Like Article
Save Article
Previous
Next
Similar Reads