[Study Notes] [C Language] comma operator, learning notes comma Operator

Source: Internet
Author: User

[Study Notes] [C Language] comma operator, learning notes comma Operator

The comma operator is mainly used to connect expressions, such:

Int a = 9; int B = 10; a = a + 1, B = 3*4;

* The expression connected by the comma operator is called a comma expression, which generally takes the following form:

Expression 1, expression 2 ,... ..., Expression n

The operation procedure of the comma expression is: from left to right, first calculate expression 1, then calculate expression 2,..., and finally calculate expression n

* The comma operator is also an operator, so it also has an operation result. The value of the entire comma expression is the value of the last expression.

Int a = 2; int B = 0; int c; c = (++ a, a * = 2, B = a * 5 ); printf ("c = % d", c );

+ The result of a is 3, the result of a * = 2 is 6, and the result of B = a * 5 is 30. Therefore, the output result is: c = 30

Note that the expression on the right is enclosed by parentheses:

C = ++ a, a * = 2, B = a * 5; printf ("c = % d", c );

The output result will be: c = 3, because c = ++ a is also part of the comma expression, which is independent of a * = 2 and B = a * 5.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.