Jul 11

A comma operator is used to separate a pair of  expressions. A pair of expressions seperate by a comma is evaluated left to right, and the type and the value of the result are the value of the type  and value of right operand.

The left side of comma operator is always evaluated to void.

Example

x = ( y – 2, y-1);

here y is assigned the value 2 and  then x the value 1 (y-1).

Parenthesis is necassary, since comma operator has lower precedence than assignment  operator.

Example

int i=2;

int j= i + ( 1,2,3,4,5);

printf(”%d” , j);

output :  7

This is because,after evaluating  expression (1,2,3,4,5),the result is 5. On adding this to i=2,results into 7

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • Blogplay
  • LinkedIn
  • MySpace
  • Reddit
  • RSS
  • Twitter

written by Shweta