Pages

Saturday, February 13, 2010

COMMA OPERATOR

Introduction
You can combine multiple expressions in a single expression using the comma operator.

Program
#include

main()
{
int i,j,k;
k = (i = 4, j = 5);
printf("k = %d",k);
}

Input

i = 4,j = 5.

Output
k = 5.

Explanation
For example, you can write: k = (i = 4, j = 5)

Here the expression is evaluated from left to right, that is, i = 4 is evaluated first then j = 5 is evaluated. The value of the rightmost expression is specified as output, thus k will get the value 5.

No comments:

Post a Comment