Predict the output of below program
#include<stdio.h> int main() { char *ptr = "geeksforgeeks"; printf("%c\n", *&*&*ptr); getchar(); return 0; } |
chevron_right
filter_none
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; } |
chevron_right
filter_none
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
Recommended Posts:
- When do we pass arguments by reference or pointer?
- Passing by pointer Vs Passing by Reference in C++
- Passing Reference to a Pointer in C++
- Difference between Call by Value and Call by Reference
- Why do we need reference variables if we have pointers
- Output of the Program | Use Macros Carefully!
- Output of the Program | Pointer to a Constant or Constant Pointer?
- Output of C++ Program | Set 1
- Output of C Program | Set 17
- Output of C++ Program | Set 2
- Output of C++ Program | Set 3
- Output of C Program | Set 18
- Output of C Program | Set 19
- Output of C Program | Set 20
- Output of C++ Program | Set 4
- Output of C++ Program | Set 5
- Output of C++ Program | Set 6
- Output of C Program | Set 21
- Output of C++ Program | Set 7
- Output of C++ Program | Set 9
Improved By : MOHAKGOEL

