C Primer Plus (5)

Source: Internet
Author: User

C uses operators to express arithmetic operations. The features of each operator include the number, priority, and combination of the required operands. When two operators share one operand, the last two features determine which operator to apply first.

5.1.1 value assignment operator: =
For example, bmw = 2002; symbol = indicates a variable name on the left and the value assigned to the variable on the right. It should be read as "assign value 2002 to variable bmw ". The action of the value assignment operator is from right to left.
A value cannot be assigned to a constant. The left side of the value assignment operator should be a modifiable left value. In fact, the left must point to a storage location.
The C90 standard adds the mona1 + operator to C without changing the value or symbol of its operand. Therefore, you can use dozen = + 12;
Several terms
Data Object: refers to the term used in the data storage area to store values.
Left value: the name or expression that identifies a specific data object.

5.1.2 division OPERATOR :/

When you perform a hybrid operation on integers and floating-point numbers, the result is a floating-point number.
The rounding process uses the largest integer smaller than or equal to the floating point number. C99 requires "Zero tail truncation", so-3.8 should be converted to-3.

5.1.3 modulo operator: %

5.1.4 increment and decrement operators: ++ and --

The advantage of using it makes the program code concise. Another advantage is that it usually produces more efficient machine language code.
Aplus = a ++; // first assign the value of a to aplus, and then increase a by 1.
Aplus = ++ a; // increase a by 1 first, and then assign the value of a to aplus.
Priority
Several precautions
If a variable appears in multiple parameters of the same function, do not use the increment or decrement operator on it.
When a variable appears in the same expression multiple times, do not use the increment or decrement operator on it.

5.2.1 expressions and statements

A statement is the basic component of a constructor. A program is a set of statements with some necessary punctuation.
For example, legs = 4 is a expression legs = 4; it is a statement.

 

5.2.2 sequence point

In C, the semicolon in the statement indicates a sequence point. It means that the value assignment operator in a statement, the incremental operator and the subtraction operator must all change before the program enters the next statement.

5.2.3 compound statement

The entire compound statement is considered as a statement.
Contraction does not work for the compiler, but you can specify the program structure for the reader.

 

In K & r c, float is automatically converted to double.
In any operation that contains two data types, both values are converted to a higher level of the two types.
In the value assignment statement, the final structure of the calculation is converted to the type of the variable to be assigned.
When passed as a function parameter, the char and short types are automatically converted to int, and float is automatically converted to double.

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.