Show: Object Pascal C++
Display Preferences

Comma Operator

From Appmethod Topics
Jump to: navigation, search

Go Up to Binary Operators Index

Syntax

expression , assignment-expression

Remarks

The comma separates elements in a function argument list.

The comma is also used as an operator in comma expressions. Mixing the two uses of comma is legal, but you must use parentheses to distinguish them.

The left operand E1 is evaluated as a void expression, then E2 is evaluated to give the result and type of the comma expression. By recursion, the expression

E1, E2, ..., En

results in the left-to-right evaluation of each Ei, with the value and type of En giving the result of the whole expression.

To avoid ambiguity with the commas in function argument and initializer lists, use parentheses. For example,

func(i, (j = 1, j + 4), k);

calls func with three arguments (i, 5, k), not four.

Personal tools
In other languages