In C/C++, precedence of Prefix ++ (or Prefix –) has higher priority than dereference (*) operator, and precedence of Postfix ++ (or Postfix –) is higher than both Prefix ++ and *.
If p is a pointer then *p++ is equivalent to *(p++) and ++*p is equivalent to ++(*p) (both Prefix ++ and * are right associative).
For example, program 1 prints ‘h’ and program 2 prints ‘e’.
// Program 1 #include<stdio.h> int main() { char arr[] = "geeksforgeeks"; char *p = arr; ++*p; printf(" %c", *p); getchar(); return 0; } |
chevron_right
filter_none
Output:
h
// Program 2 #include<stdio.h> int main() { char arr[] = "geeksforgeeks"; char *p = arr; *p++; printf(" %c", *p); getchar(); return 0; } |
chevron_right
filter_none
Output:
e
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
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:
- Operator Precedence and Associativity in C
- match_results prefix() and suffix() in C++
- Pointers in C and C++ | Set 1 (Introduction, Arithmetic and Array)
- fesetround() and fegetround() in C++ and their application
- Lex program to take input from file and remove multiple spaces, lines and tabs
- Queries to insert, delete one occurrence of a number and print the least and most frequent element
- Get first and last elements from Array and Vector in CPP
- Similarities and Differences between Ruby and C language
- Code Optimization Technique (logical AND and logical OR)
- Similarities and Differences between Ruby and C++
- Generate an array of given size with equal count and sum of odd and even numbers
- Similarities and Difference between Java and C++
- Getting System and Process Information Using C Programming and Shell in Linux
- INT_MAX and INT_MIN in C/C++ and Applications
- Difference and Similarities between PHP and C
- What are the differences between bitwise and logical AND operators in C/C++?
- Change/add only one character and print '*' exactly 20 times
- Comma in C and C++
- Return values of printf() and scanf() in C/C++
- What is return type of getchar(), fgetc() and getc() ?
Improved By : sourabh571993

