Search: in
Comma operator
Comma operator in Encyclopedia Encyclopedia
  Tutorials     Encyclopedia     Videos     Books     Software     DVDs  
       





Comma operator

In the C and C++ programming languages, the comma operator (represented by the token ,) is a binary operator that evaluates its first operand and discards the result, and then evaluates the second operand and returns this value (and type). The comma operator has the lowest precedence of any C operator, and acts as a sequence point.

The use of the comma token as an operator is distinct from its use in function calls and definitions, variable declarations, enum declarations, and similar constructs, where it acts as a separator.

In this example, the differing behavior between the second and third lines is due to the comma operator having lower precedence than assignment.

Because the comma operator discards its first operand, it is generally only useful where the first operand has desirable side effects, such as in the initialiser or the counting expression of a for loop. For example, the following terse linked list cycle detection algorithm (a version of Floyd's "tortoise and hare" algorithm):

In the OCaml and Ruby programming languages, the semicolon (";") is used for this purpose. JavaScript utilizes the comma operator in the same way C/C++ does.

See also






Source: Wikipedia | The above article is available under the GNU FDL. | Edit this article



Search for Comma operator in Tutorials
Search for Comma operator in Encyclopedia
Search for Comma operator in Videos
Search for Comma operator in Books
Search for Comma operator in Software
Search for Comma operator in DVDs
Search for Comma operator in Store




Advertisement




Comma operator in Encyclopedia
Comma_operator top Comma_operator

Home - Add TutorGig to Your Site - Disclaimer

©2011-2013 TutorGig.info All Rights Reserved. Privacy Statement