Header Ads Widget

Comma Operator

The comma operator is used to evaluate more than one expression in a single statement. Expressions are written separated by commas and the expressions are evaluated from left to right. The right most result is result is result of  compound expression.
 Consider  a = ( b = 1, c = 2, b+c );
  here value of a is 3.
Parentheses are necessary because comma operator has a lower precedence than assignment operator.
Example :
#include <stdio.h>
void main( )
{
int a, b, prod ;
prod = ( a = 5 , b = 4 , a * b ) ;
printf("Product = %d", prod);
}

Post a Comment

0 Comments