How to use comma operator in c language

coldplay.xixi
Release: 2021-02-25 15:11:21
Original
14787 people have browsed it

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.

How to use comma operator in c language

#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);
}
Copy after login

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++)
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template