C++ Syntax: Comma: ,

Description

The binary comma operator is almost only ever used for its side effects, as all it does is to ignore the value on its left and return the value on its right so
1,2
is 2. One of its common usages is to sneak extra initialisation into a for's loop init-expr e.g.:-
for ( i=0, j=0; ...
init-expr is an example of an expression whose value is not used, its only the side effect (initialisation) that matters.

See operator precedence

Other Uses for ,

The comma is also a separator (not an operator) in an argument list.

Usage Notes

None.
Go Back to the The C++ Crib Top Page


If you have any comments about this page please send them to Nick West