TestingDocs.com
Software Testing website
  • Automation
    • Selenium
    • JBehave Framework
  • Tutorials
    • MySQL Tutorials
    • Testlink
    • Maven
    • Git
  • IDEs
    • IntelliJ IDEA
    • Eclipse
  • Flowcharts
    • Flowgorithm
    • Raptor
  • About

C++

C++ Increment Operator

Overview

In this tutorial, we will learn about the C++ Increment operator with examples.

Increment Operator

The increment operator in C++ is denoted as a ++ operator symbol. We can apply the operator before or after the variable.

Pre-increment operator

A pre-increment operator is used to increment the value of the variable before using and evaluating the expression.

//Declare integer variable number
cout << “—— Pre-Increment ——-” << endl;
int number = 10;
cout << “@Before number is = ” << number << endl;
int resultExpr = ++number;
cout << “resultExpr is = ” << resultExpr << endl;
cout << “@After number is = ” << number << endl;

The value of the variable is first incremented and then used in the expression.

Output

—— Pre-Increment ——-
@Before number is = 10
resultExpr is = 11
@After number is = 11

Post-increment operator

A post-increment operatorĀ is used to increment the value of the variable after evaluating the expression.

//Declare integer variable number
cout << “—— Post-Increment ——-” << endl;
int number = 10;
cout << “@Before number is = ” << number << endl;
int resultExpr = number++;
cout << “resultExpr is = ” << resultExpr << endl;
cout << “@After number is = ” << number << endl;

The value of the variable is first used and then the variable is incremented.

C++ Increment Operator

Output

—— Post-Increment ——-
@Before number is = 10
resultExpr is = 10
@After number is = 11

That’s it.

—

C++ Tutorials

C++ Tutorials on this website:

https://www.testingdocs.com/c-coding-tutorials/

For more information on the current ISO C++ standard

https://isocpp.org/std/the-standard

Related Posts

g not found OpenSuse

C++ /

Install GCC C++ Compiler on OpenSuse

sum of digits c program

C++ /

Sum of Digits of a Number C++ Program

C++ Hello World Program

C++ /

C++ Hello World Program

C++ /

Object-Oriented Programming Language Examples

C++ /

Object-Oriented Programming Features

‹ C++ Accessor & Mutator Member Functions› C++ Decrement Operator

Recent Posts

  • MS Access Data Types
  • Install RAPTOR Avalonia on CentOS
  • Download RAPTOR Avalonia Edition on Windows
  • npm doctor command
  • Build & Run CLion Project
  • Create New CLion C Project on Windows
  • Configure CLion Toolchains on Windows
  • Launch CLion IDE on Windows
  • Activate CLion IDE
  • CLion IDE for C/C++ Development

Back to Top

Links

  • Contact
  • Privacy Policy
  • Cookie Policy

www.TestingDocs.com

Go to mobile version