The Wayback Machine - https://web.archive.org/web/20240118181614/https://www.geeksforgeeks.org/dereference-reference-dereference-reference/
Open In App
Related Articles

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

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report

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


Learn to code easily with our course Coding for Everyone. This course is accessible and designed for everyone, even if you're new to coding. Start today and join millions on a journey to improve your skills!

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!

Commit to GfG's Three-90 Challenge! Purchase a course, complete 90% in 90 days, and save 90% cost click here to explore.
Last Updated : 09 Aug, 2018
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads