[C ++ primer] Chapter 5 loop and relational expressions

Source: Internet
Author: User

1. For Loop

1. Each expression in c ++ has a value;

Int A = 0 // declaration expression

23 + 17 // Mathematical Expression

A = (B = 3) + 4 // The value of A is 7

2. Differences Between Expressions and statements

When the expression is added with ";", it is the statement.

Expression A = 10

A = 10; for statements

3. prefix and suffix

++ I; faster and more efficient than I ++;

[Note] the prefix increment (++), prefix increment (++), and unreference (*) have the same priority;

And combine rules from right to left

For example, * ++ pt; // first apply ++ to PT and then * to PT.

4. Comma Operator

The value of the comma expression is the value of the second part.

Expression: the value of I = 20, j = 30 is 30 (the value of the second part)

Cats = (I = 20, j = 30);

5. relational expressions (Relational operators: <,>, >=, =)

The priority of Relational operators is lower than that of Arithmetic Operators x + 3> the y-4 should be (x + 3)> (y-4)

The non-zero value is true, and the zero value is false.

6. Comparison of C-style strings

WORD = "mate"; array name word indicates the address of the array. constants enclosed in quotation marks are also the address of the array.

Strcpm (str1, str2); // str1 = str2 returns 0; If str1 is placed before str2 in alphabetical order, strcpm (ABC, BBC) returns a negative number.






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.