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
  • DSA
  • Practice Problems
  • Python
  • C
  • C++
  • Java
  • Courses
  • Machine Learning
  • DevOps
  • Web Development
  • System Design
  • Aptitude
  • Projects
Open In App
Next Article:
Assignment Operators in Programming
Next article icon

Increment and Decrement Operators in Programming

Last Updated : 26 Mar, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

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 Operators
  • Increment Operators in C
  • Increment Operators in C++
  • Increment Operators in Java
  • Increment Operators in Python
  • Increment Operators in C#
  • Increment Operators in JavaScript
  • Decrement Operators
  • Decrement Operators in C
  • Decrement Operators in C++
  • Decrement Operators in Java
  • Decrement Operators in Python
  • Decrement Operators in C#
  • Decrement Operators in JavaScript
  • Difference between Increment and Decrement Operator

Increment Operators:

Increment operators are used in programming languages to increase the value of a variable by one. There are two types of increment operators: the prefix increment operator (++x) and the postfix increment operator (x++).

Prefix Increment Operator (++x):

  • The prefix increment operator increases the value of the variable by 1 before the value is used in the expression.
  • Syntax: ++x
  • Example: If x is initially 5, ++x will increment x to 6 and return the new value (6).

Postfix Increment Operator (x++):

  • The postfix increment operator increases the value of the variable by 1 after the value is used in the expression.
  • Syntax: x++
  • Example: If x is initially 5, x++ will return the current value of x (5) and then increment x to 6.

Increment Operators in C:

Below is the implementation of Increment Operator in C:

C
#include <stdio.h>  int main() {     int x = 5;      // Prefix increment: increment x by 1 and then print the     // value (6)     printf("%d\n", ++x);     // Postfix increment: print the value of x (6) and then     // increment x by 1     printf("%d\n", x++);     // Output: 7     printf("%d\n", x);      return 0; } 

Output
6 6 7 

Increment Operators in C++:

Below is the implementation of Increment Operator in C++:

C++
#include <iostream> using namespace std;  int main() {     int x = 5;     // Prefix increment: increment x by 1 and then print the     // value (6)     cout << ++x << endl;     // Postfix increment: print the value of x (6) and then     // increment x by 1     cout << x++ << endl;     // Output: 7     cout << x << endl;     return 0; } 

Output
6 6 7 

Increment Operators in Java:

Below is the implementation of Increment Operator in Java:

Java
public class Main {     public static void main(String[] args)     {         int x = 5;         // Prefix increment: increment x by 1 and then print         // the value (6)         System.out.println(++x);         // Postfix increment: print the value of x (6) and         // then increment x by 1         System.out.println(x++);         // Output: 7         System.out.println(x);     } } 

Output
6 6 7 

Increment Operators in Python:

There are no increment(++) or decrement(--) operators in programming. If we need to increment or decrement the value of a variably by 1, then we can use the increment assignment(+=) or decrement assignment(-=) operators. Below is the implementation:

Python
x = 5  # Prefix increment: increment x by 1 and then print the # value (6) print(x + 1) x += 1 # Postfix increment: print the value of x (6) and then # increment x by 1 print(x) x += 1 # Output: 7 print(x) 

Output
6 6 7 

Increment Operators in C#:

Below is the implementation of Increment Operator in C#:

C#
using System;  class Program {     static void Main()     {         int x = 5;          // Prefix increment: increment x by 1 and then print         // the value (6)         Console.WriteLine(++x);         // Postfix increment: print the value of x (6) and         // then increment x by 1         Console.WriteLine(x++);         // Output: 7         Console.WriteLine(x);     } } 

Output
6 6 7 

Increment Operators in JavaScript:

Below is the implementation of Increment Operator in Javascript:

JavaScript
let x = 5;  // Prefix increment: increment x by 1 and then print the // value (6) console.log(++x); // Postfix increment: print the value of x (6) and then // increment x by 1 console.log(x++); // Output: 7 console.log(x); 

Output
6 6 7 

Decrement Operators:

Decrement operators are used in programming languages to decrease the value of a variable by one. Similar to increment operators, there are two types of decrement operators: the prefix decrement operator (--x) and the postfix decrement operator (x--).

Prefix Decrement Operator (--x):

  • The prefix decrement operator decreases the value of the variable by 1 before the value is used in the expression.
  • Syntax: --x
  • Example: If x is initially 5, --x will decrement x to 4 and return the new value (4).

Postfix Decrement Operator (x--):

  • The postfix decrement operator decreases the value of the variable by 1 after the value is used in the expression.
  • Syntax: x--
  • Example: If x is initially 5, x-- will return the current value of x (5) and then decrement x to 4.

Decrement Operators in C:

Below is the implementation of Decrement Operator in C:

C
#include <stdio.h>  int main() {     int x = 5;      // Prefix decrement: decrement x by 1 and then print the     // value (4)     printf("%d\n", --x);     // Postfix decrement: print the value of x (4) and then     // decrement x by 1     printf("%d\n", x--);     // Output: 3     printf("%d\n", x);      return 0; } 

Output
4 4 3 

Decrement Operators in C++:

Below is the implementation of Decrement Operator in C++:

C++
#include <iostream> using namespace std;  int main() {     int x = 5;     // Prefix decrement: decrement x by 1 and then print the     // value (4)     cout << --x << endl;     // Postfix decrement: print the value of x (4) and then     // decrement x by 1     cout << x-- << endl;     // Output: 3     cout << x << endl;     return 0; } 

Output
4 4 3 

Decrement Operators in Java:

Below is the implementation of Decrement Operator in Java:

Java
public class Main {     public static void main(String[] args)     {         int x = 5;         // Prefix decrement: decrement x by 1 and then print         // the value (4)         System.out.println(--x);         // Postfix decrement: print the value of x (4) and         // then decrement x by 1         System.out.println(x--);         // Output: 3         System.out.println(x);     } } 

Output
4 4 3 

Decrement Operators in Python:

Below is the implementation of Decrement Operator in Python:

Python
x = 5  # Prefix decrement: decrement x by 1 and then print the # value (4) x -= 1 print(x) # Postfix decrement: print the value of x (4) and then # decrement x by 1 print(x) x -= 1 # Output: 3 print(x) 

Output
4 4 3 

Decrement Operators in C#:

Below is the implementation of Decrement Operator in C#:

C#
using System;  class Program {     static void Main() {         int x = 5;          // Prefix decrement: decrement x by 1 and then print the         // value (4)         Console.WriteLine(--x);         // Postfix decrement: print the value of x (4) and then         // decrement x by 1         Console.WriteLine(x--);         // Output: 3         Console.WriteLine(x);     } } 

Output
4 4 3 

Decrement Operators in Javascript:

Below is the implementation of Decrement Operator in Javascript:

JavaScript
let x = 5;  // Prefix decrement: decrement x by 1 and then print the // value (4) console.log(--x); // Postfix decrement: print the value of x (4) and then // decrement x by 1 console.log(x--); // Output: 3 console.log(x); 

Output
4 4 3 

Difference between Increment and Decrement Operator:

Aspect

Increment Operator (++)

Decrement Operator (--)

Operation

Increases the value of a variable by 1.

Decreases the value of a variable by 1.

Syntax

variable++ or ++variable

variable-- or --variable

Order of Execution

Post-increment (returns current value, then increments)

Pre-increment (increments first, then returns updated value)

Post-decrement (returns current value, then decrements)

Pre-decrement (decrements first, then returns updated value)

Usage

Often used in loops and calculations to iterate or count.

Useful in similar scenarios where decreasing the value is necessary, such as decreasing a counter or looping backwards.

Examples

int x = 5;
x++; // x is now 6
++x; // x is now 7

int y = 10;
int y = 10;
--y; // y is now 8


Next Article
Assignment Operators in Programming

S

srinam
Improve
Article Tags :
  • Programming

Similar Reads

  • 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
  • C++ Increment and Decrement Operators
    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 a
    4 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
  • Assignment Operators in Programming
    Assignment operators in programming are symbols used to assign values to variables. They offer shorthand notations for performing arithmetic operations and updating variable values in a single step. These operators are fundamental in most programming languages and help streamline code while improvin
    7 min read
  • Logical AND operator in Programming
    In programming, Logical operators play a crucial role in manipulating individual data. One of the fundamental logical operators is the Logical AND operator(&&).In this article, we’ll discuss what is a Logical AND operator, its syntax, properties, applications, and optimization techniques, an
    5 min read
  • Bitwise AND operator in Programming
    In programming, Bitwise Operators play a crucial role in manipulating individual bits of data. One of the fundamental bitwise operators is the Bitwise AND operator (&). In this article, we'll dive deep into what is Bitwise AND operator, its syntax, properties, applications, and optimization tech
    6 min read
  • Comparison Operators in Programming
    Comparison Operators in programming are used to compare values and determine their relationship, such as equality, inequality, greater than, less than, etc. They evaluate expressions and return a Boolean value (true or false) based on the comparison result, crucial for decision-making in conditional
    10 min read
  • What are Operators in Programming?
    Operators in programming are essential symbols that perform operations on variables and values, enabling tasks like arithmetic calculations, logical comparisons, and bitwise manipulations. In this article, we will learn about the basics of operators and their types. Table of Content What are Operato
    15+ min read
  • Binary Operators in Programming
    Binary Operators are essential tools in programming that perform operations on pairs of data, enabling tasks like calculations, comparisons, logical operations, and bitwise manipulations. They are fundamental for processing and manipulating data efficiently in computer programs. Table of Content Wha
    14 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