What is the built-in comma operator in C++?
The comma operator evaluates all of its operands from left to right and returns the value of the last one.
Syntax
expr1, expr2, expr3...
Where expr1, expr2, expr3... is one or more expressions, the last of which is returned as the value of the comma operator expression.
Code
#include <iostream>int main() {int n = 1;int m = (++n, // n = n + 1 = 1 + 1 = 2std::cout << "n = " << n << '\n', // Displays "n = 2"++n, // n = n + 1 = 2 + 1 = 32 * n // 2 * 3 = 6); // The operands are executed sequentially,// the result of the last expression is assigned// to a variable: 2 * n = 2 * 3 = 6std::cout << (++m, m); // First operand evaluates// and its result is discarded,// expression evaluates to// 7}