-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
  • 912
  • 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
  • 17,715
  • 5
  • 39
  • 50
7

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

zildjohn01
  • 11,099
  • 6
  • 49
  • 56
3

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

Remy Lebeau
  • 505,946
  • 29
  • 409
  • 696
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
  • 302,239
  • 39
  • 506
  • 752