0X05 operator, expression and statement, 0x05 Operator

Source: Internet
Author: User

0X05 operator, expression and statement, 0x05 Operator

If you have strong logic capabilities or have been thinking for a long time, you can write a complicated expression. But to make the code easier to read, the best expression should not exceed three operators. (The statement here does not contain code blocks.) using auto-increment or auto-increment may be more professional, but you must know the difference between ++ before and after, as you can see from the location, ++ first adds one, And ++ adds one after it is used.

Expression: an expression is composed of operators and operands. An important attribute of C language is that each C expression has a value.

Statement (statement) is the basic part of the constructor. A program (program) is a collection of statements with some necessary punctuation. A statement is a complete computer instruction. The C language requires that each statement must end with a semicolon, which is the ";"

C regards any expression with a semicolon as a statement. You can "a;", "4;", and ";". They are all permitted by C.

Dropping semicolons is a very easy-to-use error. It may not take it for granted at the beginning, but it can always be lost inadvertently.

Side effect is used to modify data objects or files. For example, for the I used in the for loop, the purpose of using I is to count the loop, but the side effect is that the I value changes after the end of the loop, when I is used in the next for loop, it needs to be reinitialized.

Sequence point is a point in program execution. At this point, all side effects are calculated before going to the next step. Each semicolon in C indicates a sequence point.

Compound statement:

Two or more statements organized by curly brackets. It is also called a code block (code block // is also a C, C ++ IDE)

Without curly braces, the scope of if, for, and while code blocks starts from them to the next semicolon.

Type conversion:

The basic rules are as follows:

1. When the signed and unsigned char and short types appear in the expression, they are automatically converted to int. If necessary, they are automatically converted to unsigned int.

2. In any operation that contains two data types, both values will be converted to a higher level of either.

3. The sequence from high to low is long double, double, float, unsigned long, long, unsigned long, long, unsigned int, and int.

4. In the value assignment statement, the final result of the calculation is converted to the type of the variable to be assigned.

5. passed as a function parameter: char and short will be converted to int, float will be converted to double

There is usually no problem with type conversion, but type downgrade may cause problems

To force type conversion, use the assignment operator (type). For example, convert a of the int type to long, (long);

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.