Friday, March 2, 2012

The Comma Operator


The operator strings together several expressions.The left side of the comma operator is always evaluated as void.This means that the expression on the right side becomes the value of the total comma-separated expression.For example,
x=(y=3,y+1);
first assigns y the value 3 and then assigns x the value 4.The parentheses are necessary because the comma operator has a lower precedence than the assignment operator.Essentially the comma causes a sequence of operations.When you use it on the right side of an assignment statement,the value assigned is the value of the last expression of the comma-separated list.
The comma operator has somewhat the same meaning as the word "and" in normal English as used in the phrase "do this and this and this".

No comments:

Post a Comment