- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Pre-increment and Post-increment in C/C++
Here we will see what is the pre-increment and post-increment in C or C++. The pre-increment and post-increment both are increment operators. But they have little differences.
The pre-increment operator increments the value of a variable at first, then sends the assign it to some other variable, but in the case of postincrement, it at first assign to a variable, then increase the value.
Example
#include<iostream> using namespace std; main() { int x, y, z; x = 10; y = 10; z = ++x; //z will hold 11 cout << "Z: " << z << endl; z = y++; //z will hold 10, then y will be 11 cout << "Z: " << z << " and y is: " << y << endl; }
Output
Z: 11 Z: 10 and y is: 11
The precedence of post increment is more than precedence of pre increment, and their associativity is also different. The associativity of pre increment is right to left, of post increment is left to right.
- Related Articles
- Pre-increment and Post-increment concept in C/C++?
- Write a C program to demonstrate post increment and pre increment operators
- Pre & post increment operator behavior in C, C++, Java, and C#
- Pre-increment (or pre-decrement) in C
- Increment ++ and decrement -- Operators in C++
- Increment and Decrement Operators in C#
- Increment ++ and Decrement -- Operator Overloading in C++
- Post and Pre incremented of arrays in C language
- What are increment (++) and decrement (--) operators in C#?
- Way to increment a character in C#
- Amortized analysis for increment in counter in C++
- Design a Stack With Increment Operation in C++
- Minimum Increment to Make Array Unique in C++
- Increment and decrement operators in Java
- Increment and Decrement Operators in Python?

Advertisements