Output of the program | Dereference, Reference, Dereference, Reference….
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
Recommended Posts:
- Output of C++ Program | Set 20
- Output of C++ Program | Set 19
- Output of C Program | Set 29
- Output of C program | Set 25
- Output of C Program | Set 26
- Output of C Program | Set 28
- Output of C++ Program | Set 11
- Output of C++ Program | Set 12
- Output of C Program | Set 27
- Output of C++ Program | Set 8
- Output of C++ Program | Set 13
- Output of C++ Program | Set 16
- Output of C++ Program | Set 4
- Output of C++ Program | Set 5
- Output of C++ Program | Set 6
Improved By : MOHAKGOEL



