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 email@example.com. 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.
GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details
- Rust vs C++: Will Rust Replace C++ in Future ?
- Priority queue of pairs in C++ with ordering by first and second element
- Implementation of lower_bound() and upper_bound() in Vector of Pairs in C++
- Generating RGBA portable graphic images through C++
- std::basic_istream::ignore in C++ with Examples
- std::basic_istream::getline in C++ with Examples
- Format specifiers in different Programming Languages
- C program to find square root of a given number
- C program to print odd line contents of a File followed by even line content
- std::is_heap( ) in C++ with Examples
- std::basic_istream::gcount() in C++ with Examples
- new vs malloc() and free() vs delete in C++
- std::string::rfind in C++ with Examples
- Sum of factorials of Prime numbers in a Linked list
- Sum of all Palindrome Numbers present in a Linked list