Home > Article > Backend Development > How to use comma operator in c language
How to use the comma operator in c language: When used in sequence, the combination order is from left to right, and is used for sequential evaluation. After completion, the value of the entire expression is the value of the last expression.
#The operating environment of this article: Windows 7 system, Dell G3 computer.
How to use the comma operator in C language:
1. Usage:
1. Use it when ordering, The combination order is from left to right and is used for sequential evaluation. After completion, the value of the entire expression is the value of the last expression.
main() {int a,s,d; s=2; d=3; a=12+(s+2,d+4); }
First calculate the value in the brackets: s 2=4, d 4=7; the brackets should be (4,7), the value in the brackets only takes the last one, if there are no brackets, take the first one ;a=12 7=19.
x=(y=3,(z = y 2) 5); first assigns y to 3, increments y to 4, then adds 4 to 2, and assigns the result 6 to z, Next add 5 to z and finally assign x to the resulting value of 11.
2. Note: The comma operator ( , ) is the operator with the lowest priority among C language operators.
2. Other usages:
1. Application in for:
int i;int j; for(i=0,j=0;i<5;i++,j++)
2. When separator: int i,j;
Related learning recommendations: C language tutorial video
The above is the detailed content of How to use comma operator in c language. For more information, please follow other related articles on the PHP Chinese website!