"Learning note", "C language" comma operator

Source: Internet
Author: User

The comma operator is primarily used for connection expressions, such as:

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

* An expression concatenated with the comma operator is called a comma expression, and its general form is:

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

The operation of the comma expression is: From left to right, evaluates expression 1, evaluates expression 2, ..., and evaluates 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);p rintf ("c =%d", c);

The result of ++a is 3,a *= 2 results for 6,b = A * 5 result is 30. As a result, the output is: c = 30

It is important to note that the right expression is wrapped in parentheses (), if not enclosed in parentheses, that is:

c = ++a, a *= 2, b = A * 5;printf ("c =%d", c);

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

"Learning note", "C language" comma operator

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.