Search code examples
c++variablesdecrement

How to decrement several variables in C++in a single line statement?


Edit: I replaced the phrase 'in one line' by 'in a single line statement' since this is what I was looking for

Let's say we have the following variables at hand:

int a = 5;
int b = 9;

Is there a way to compress this ...

a--;
b--;

... into in a single line statement?? The question is not about decrementing multiple variables in a for loop, since this seems to be a common yet unrelated question.


Solution

  • You probably mean "in a single statement", not just "in a single line". Then you can use the comma-operator:

    (a--,b--);