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++ Decrement Operator

Overview

In this tutorial, we will learn about C++ Decrement Operator with examples.

Decrement Operator

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

Pre-decrement operator

A pre-decrement operator is used to decrement the value of the variable before evaluating the expression.

cout << “—— Post-Decrement ——-” << 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 decremented and then used in the expression.

Post-decrement operator

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

cout << “—— Post-Decrement ——-” << 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 used in the expression and decremented after that.

C++ Decrement Operator

—— Post-Decrement ——-
@Before number is = 10
resultExpr is = 10
@After number is = 9

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++ Increment Operator› C++ Modulus 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