Search
 
SCRIPT & CODE EXAMPLE
 

CPP

how to use decrement operator in c++

#include <iostream>
using namespace std;

int main()
{
  int x = 5, y = 5;
  
  cout << x-- << " " << --y ;
  // Outputs 5 4
  
  return 0;
}
Comment

C++ Increment and Decrement

	int b, a, e, d, c, f;
    int num = 57;
    cout << "The number is " << num << endl;

    b = ++num;
    a = ++num;
    e = a + 1;
    cout << "After post increment by 1, the number is " << b << endl;
    cout << "After pre increment by 1, the number is " << a << endl;
    cout << "After increasing by 1, the number is " << e << endl;

    d = --e;
    c = --e;
    f = c - 1;
    cout << "After post decrement by 1, the number is " << d << endl;
    cout << "After pre decrement by 1, the number is " << c << endl;
    cout << "After decreasing by 1, the number is " << f << endl;
Comment

C++ Short-Circuit Operators_Increment and Decrement

Example 5-24. Overloading the increment operator
enum status { stopped, running, waiting };
status& operator++(status& s) { // Prefix
 if (s != waiting)
 s = status(s + 1);
 return s;
}
status operator++(status& s, int) { // Postfix
 status rtn = s;
 ++s;
 return rtn;
}
int main( )
{
 status s(stopped);
 ++s; // Calls operator++(s);
 s++; // Calls operator++(s, 0);
}
Comment

decrement c++

int x = 5;
x--;
cout << x << endl;
//outputs 4
Comment

PREVIOUS NEXT
Code Example
Cpp :: how to round to nearest whole number unity 
Cpp :: sort stl 
Cpp :: c++ hide show console 
Cpp :: cpp unions 
Cpp :: c++ construnctor 
Cpp :: length of string c++ 
Cpp :: What should main() return in C++? 
Cpp :: prime numbers less than a given number c++ 
Cpp :: c++ length of char array 
Cpp :: search a word in cpp file 
Cpp :: convert binary string to int c++ 
Cpp :: c++ call method in same class 
Cpp :: cpp create multidimensional vector 
Cpp :: primes in range cpp 
Cpp :: c++ factorial 
Cpp :: docker.io : Depends: containerd (= 1.2.6-0ubuntu1~) E: Unable to correct problems, you have held broken packages 
Cpp :: increment c++ 
Cpp :: ViewController import 
Cpp :: Quicksort taking random pivot 
Cpp :: c++ vectors 
Cpp :: how to initialize array with new in c++ 
Cpp :: remove from vector by value c++ 
Cpp :: continue statement in c++ program 
Cpp :: draw rectangle opencv c++ 
Cpp :: 3d projection onto 2d plane algorithm 
Cpp :: string split by space c++ 
Cpp :: unordered_set to vector 
Cpp :: c++ capture screen as pixel array 
Cpp :: c++ erase remove 
Cpp :: c++ string slicing 
ADD CONTENT
Topic
Content
Source link
Name
4+5 =