
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 Concept in C/C++
Increment operators are used to increase the value by one while decrement works opposite increment. Decrement operator decrease the value by one.
Pre-increment (++i) − Before assigning the value to the variable, the value is incremented by one.
Post-increment (i++) − After assigning the value to the variable, the value is incremented.
The following is the syntax of pre and post increment.
++variable_name; // Pre-increment variable_name++; // Post-increment
Here,
variable_name − Any name of the variable given by user.
Here is an example of pre and post increment in C++.
Example
#include <iostream> using namespace std; int main() { int i = 5; cout << "The pre-incremented value: " << i; while(++i < 10 ) cout<<"\t"<<i; cout << "\nThe post-incremented value: " << i; while(i++ < 15 ) cout<<"\t"<<i; return 0; }
Output
The pre-incremented value: 5 6 789 The post-incremented value: 10 1112131415
Advertisements