C Tutorial/Operator/Comma Operator

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

Comma operator

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


#include<stdio.h>
main(){
  int i,j,k;
  k = (i = 4, j = 5);
  printf("k = %d",k);
}
k = 5

Comma operator can return a value.

Comma operator returns the value of the rightmost operand.


#include<stdio.h>
main(){
    int i, j;
   
    printf("%d",(i = 0, j = 10));
}
10