C Tutorial/Operator/Comma Operator

Материал из C\C++ эксперт
Перейти к: навигация, поиск

Comma operator

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


<source lang="cpp">#include<stdio.h> main(){

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

}</source>

k = 5

Comma operator can return a value.

Comma operator returns the value of the rightmost operand.


<source lang="cpp">#include<stdio.h> main(){

   int i, j;
  
   printf("%d",(i = 0, j = 10));

}</source>

10