Comma operator ( , )
The comma operator (,) is used to separate two or more expressions that are included where only one expression
is expected. When the set of expressions has to be evaluated for a value, only the rightmost expression is
considered.
For example, the following code:
a = (b=3, b+2);
Would first assign the value 3 to b, and then assign b+2 to variable a. So, at the end, variable a would contain the
value 5 while variable b would contain value 3.
The comma operator (,) is used to separate two or more expressions that are included where only one expression
is expected. When the set of expressions has to be evaluated for a value, only the rightmost expression is
considered.
For example, the following code:
a = (b=3, b+2);
Would first assign the value 3 to b, and then assign b+2 to variable a. So, at the end, variable a would contain the
value 5 while variable b would contain value 3.
Learn More :
Operators
- Operating with variables in C++
- Assignment operator (=) in C++
- Arithmetic operators ( +, -, , , % ) in C++
- Increase and decrease (++, --) operators in C++
- Relational and equality operators ( ==, !=, >, <, >=, <= ) in C++
- Logical operators ( !, &&, || ) in C++
- Conditional operator ( ? ) in C++
- Bitwise Operators ( &, |, ^, ~, <<, >> )
- Precedence of Operators in C++