-1

Possible Duplicate:
C++ Comma Operator

what is result of operator ',' by standard? Last argument? in code like this, for example:

int a = 0;
int b = 1;

while(a,b);

or using it like this is not allowed? MSVS thiks that result is b, is it true?

sorry for duplicating, did not know how this operator called in english )

Community
  • 1
  • 1
ShPavel
  • 962
  • 1
  • 10
  • 17

4 Answers4

8

The sequence of statements is executed and the return value is the evaluation of the final statement.

Amardeep AC9MF
  • 18,464
  • 5
  • 40
  • 50
7

The comma operator always returns its last argument, unless the operator is overloaded.

zildjohn01
  • 11,339
  • 6
  • 52
  • 58
3

The result of the ',' operator is the last evaluated expression, yes.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
1

The result of , operator is its right-hand operand, i.e. the subexpression that follows ,.

Operator , is left-associative, meaning that if you have a chain of several , operators with operands and no braces, then the last subexpression in the chain is the result.

AnT stands with Russia
  • 312,472
  • 42
  • 525
  • 765