Pre-increment operator: A pre-increment operator is used to increment the value of a variable before using it in a expression. In the Pre-Increment, value is first incremented and then used inside the expression.
a = ++x;
Here, if the value of ‘x’ is 10 then value of ‘a’ will be 11 because the value of ‘x’ gets modified before using it in the expression.
Pre Increment Operation a = 11 x = 11
Post-increment operator: A post-increment operator is used to increment the value of variable after executing expression completely in which post increment is used. In the Post-Increment, value is first used in a expression and then incremented.
a = x++;
Here, suppose the value of ‘x’ is 10 then value of variable ‘b’ will be 10 because old value of ‘x’ is used.
Post Increment Operation a = 10 x = 11
Evaluating post and pre-increment together
Precedence of postfix ++ is more than prefix ++ and their associativity is also different. Associativity of prefix ++ is right to left and associativity of postfix ++ is left to right.
- Associativity of postfix ++ is left to right
- Associativity of prefix ++ is right to left
You may also like:
This article is contributed by Souvik Nandi. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Strict Aliasing Rule in C with Examples
- Difference between cout and puts() in C++ with Examples
- Difference between forward list and list in C++
- Short-Circuiting in C++ and Linux
- Different types of range-based for loop iterators in C++
- Learn C++ Programming Step by Step - A 20 Day Curriculum!
- Difference between C and Dart
- Difference between Sentinel and Counter Controlled Loop in C
- Why do we need reference variables if we have pointers
- What are the differences between C and Embedded C?
- Similarities and Difference between Java and C++
- Macros and its types in C/C++
- Reversed Range-based for loop in C++ with Examples
- How to find index of a given element in a Vector in C++
- Introduction to Complex Objects and Composition