Comma Operator :
Comma operator is a set of expression separated by comma is a valid constant in the C language. For example i and j are declared by the statements
int i , j;
i=(j=10,j+20);
In the above declaration, right hand side consists of two expressions separated by comma. The first expression is j=10 and second is j+20. These expressions are evaluated from left to right. ie first the value 10 is assigned to j and then expression j+20 is evaluated so the final value of i will be 30.
C – COMMA OPERATOR EXAMPLE PROGRAM:
1 2 3 4 5 6 7 8 9 10 |
#include<stdio.h> #include<conio.h> void main() { int i, j; clrscr(); i=(j=10, j+20); printf(“i = %d\n j = %d\n” , i,j ); getch(); } |
Output :
i = 30
j = 10 |