Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • C++ Data Types
  • C++ Input/Output
  • C++ Arrays
  • C++ Pointers
  • C++ OOPs
  • C++ STL
  • C++ Interview Questions
  • C++ Programs
  • C++ Cheatsheet
  • C++ MCQ
  • C++ Projects
  • C++ Exception Handling
  • C++ Memory Management
Open In App
Next Article:
Increment and Decrement Operators in C
Next article icon

C++ Increment and Decrement Operators

Last Updated : 27 Nov, 2022
Comments
Improve
Suggest changes
Like Article
Like
Report

Prerequisite: Operators in C++

What is a C++ increment Operator?

 The C++ increment operator is a unary operator. The symbol used to represent the increment operator is (++). The increment operator increases the value stored by the variable by 1. This operator is used for Numeric values only.

There are two types of C++ increment Operator: 

  • Pre-Increment
  • Post-Increment

1. Post-Increment operator (a++)

The postfix operator says that first use the value and then increment it. This means the value is first used up for the operation then the value is updated by 1.

Example:

C++
// C++ Program to implement // Post-Increment #include <iostream>  using namespace std;  int main() {      int x = 5;     cout << "Value before using post increment operator is "             ": "          << x << endl;     int temp = x++;     cout << "The value stored by temp is : " << temp          << endl;     cout << "After using the post increment operator is : "          << x << endl;     return 0; } 

Output
Value before using post increment operator is : 5  The value stored by temp is : 5  After using the post increment operator is : 6

2. Pre-increment operator(++a)

The postfix operator says that first increment the value then use it. This means the value is increased by 1 for the operation then the value is used by the variable

Example: 

C++
// C++ Program to implement // Pre-Increment #include <iostream>  using namespace std;  int main() {      int x = 5;     cout         << "Value before using pre increment operator is : "         << x << endl;     int temp = ++x;     cout << "The value stored by temp is : " << temp          << endl;     cout << "After using the post increment operator is : "          << x << endl;     return 0; } 

Output
Value before using pre increment operator is : 5  The value stored by temp is : 6  After using the post increment operator is : 6

What is a C++ decrement Operator?

The C++ decrement operator is a unary operator. The symbol used to represent the increment operator is (--). The decrement operator decreases the value stored by the variable by 1. This operator is used for Numeric values only.

There are two types of C++ decrement Operator:

  • Post-decrement operator
  • Pre-decrement operator

1. Post-decrement operator (a--): 

The postfix operator says that first use the value and then decrease it. This means the value is first used up for the operation then the value is decreased by 1.

Example: 

C++
// C++ Program to implement // Post-Decrement #include <iostream>  using namespace std;  int main() {      int x = 5;     cout << "Value before using post decrement operator is "             ": "          << x << endl;     int temp = x--;     cout << "The value stored by temp is : " << temp          << endl;     cout << "After using the post decrement operator is : "          << x << endl;     return 0; } 

Output
Value before using post decrement operator is : 5  The value stored by temp is : 5  After using the post decrement operator is : 4

2. Pre-decrement operator (--a)

The postfix operator says that first decrease the value and then use it. This means the value is decreased by 1 for the operation then the value is used by the variable

Example:

C++
// C++ Program to implement // Pre-Decrement #include <iostream>  using namespace std;  int main() {      int x = 5;     cout         << "Value before using pre-decrement operator is : "         << x << endl;     int temp = --x;     cout << "The value stored by temp is : " << temp          << endl;     cout << "After using the pre-decrement operator is : "          << x << endl;     return 0; } 

Output
Value before using pre-decrement operator is : 5  The value stored by temp is : 4  After using the pre-decrement operator is : 4

Next Article
Increment and Decrement Operators in C

R

raj2002
Improve
Article Tags :
  • Technical Scripter
  • C++
  • Technical Scripter 2022
  • cpp-operator
Practice Tags :
  • CPP
  • cpp-operator

Similar Reads

  • Increment and Decrement Operators in C
    The increment ( ++ ) and decrement ( -- ) operators in C are unary operators for incrementing and decrementing the numeric values by 1 respectively. The incrementation and decrementation are one of the most frequently used operations in programming for looping, array traversal, pointer arithmetic, a
    4 min read
  • Increment (++) and Decrement (--) Operator Overloading in C++
    Operator overloading is a feature in object-oriented programming which allows a programmer to redefine a built-in operator to work with user-defined data types. Why Operator Overloading? Let's say we have defined a class Integer for handling operations on integers. We can have functions add(), subtr
    4 min read
  • Increment and Decrement Operators in Programming
    Increment and Decrement Operators are Unary Operators commonly used in programming to increase or decrease the value of a variable by one, respectively. They provide a shorthand way to perform these common operations. Table of Content Increment OperatorsIncrement Operators in CIncrement Operators in
    7 min read
  • Pre-increment and Post-increment in C/C++
    In C/C++, Increment operators are used to increase the value of a variable by 1. This operator is represented by the ++ symbol. The increment operator can either increase the value of the variable by 1 before assigning it to the variable or can increase the value of the variable by 1 after assigning
    3 min read
  • C# Program to Overload Unary Increment (++) and Decrement (--) Operators
    In C#, overloading is the common way of implementing polymorphism. It is the ability to redefine a function in more than one form. A user can implement method overloading by defining two or more methods in a class sharing the same name but with different method signatures. So in this article, we wil
    3 min read
  • Pre Increment and Post Increment Operator in Programming
    Pre Increment Operator and Post Increment Operator are the two ways of using the Increment operator to increment the value of a variable by 1. They can be used with numeric data values such as int, float, double, etc. Pre-increment and Post-increment perform similar tasks with minor distinctions. In
    6 min read
  • Pre and Post Decrement Operator in Programming
    Pre-decrement and post-decrement are the two ways of using the decrement operator to decrement the value of a variable by 1. They can be used with numeric data type values such as int, float, double, etc. Pre-decrement and Post-decrement perform similar tasks with minor distinctions. Table of Conten
    5 min read
  • Increment (Decrement) operators require L-value Expression
    What will be the output of the following program? #include<stdio.h> int main() { int i = 10; printf("%d", ++(-i)); return 0; } A) 11 B) 10 C) -9 D) None Answer: D, None - Compilation Error. Explanation: In C/C++ the pre-increment (decrement) and the post-increment (decrement) operato
    1 min read
  • Assignment Operators in C
    In C, assignment operators are used to assign values to variables. The left operand is the variable and the right operand is the value being assigned. The value on the right must match the data type of the variable otherwise, the compiler will raise an error. Let's take a look at an example: [GFGTAB
    5 min read
  • Assignment Operators in C++
    In C++, the assignment operator forms the backbone of computational processes by performing a simple operation like assigning a value to a variable. It is denoted by equal sign ( = ) and provides one of the most basic operations in any programming language i.e. assign some value to the variables in
    6 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences