C Primer Plus Reading notes the fifth chapter

Source: Internet
Author: User
Tags integer division

The headings in this chapter are operators, expressions, and statements. The main research is how to deal with data.

The sample code shows a very difficult code that uses a simple while loop.

The basic concepts of this chapter are briefly described below.

1. Basic operator.

The basic operators are: assignment operators (c can be assigned multiple values, such as Cheeta = Tarzan = 68), addition operations, subtraction operators, symbolic operators (also known as unary operators), multiplication operators, Division operators (integer division results are discarded, and integers are in addition to floating point numbers). The compiler converts integers to floating-point numbers first

2. Other operators

There are sizeof,size_t,% (note the case of negative numbers), ++,--(the author says in the book, if you still use i = i + 1; This statement, no one will think you are a C-language programmer ... )

The emphasis here is on the precedence of the increment and decrement operators: only parentheses are higher than them. The following code: y = 2; n = 3; Nextnum = (y + n++) * 6; The value of Nextnum is 30. This is because n is incremented to 4 only if the value of n is used. The priority description + + is only owned by N, not y + N. It is possible to remember that when n++ occurs, n is used first, then the value of n is increased, and when ++n occurs, the value of n is incremented before it is used. Because the C compiler can choose to calculate the parameters of the function first, you do not know in what order the compiler operates.

Principle: 1. If a variable appears in multiple parameters of the same function, do not use increment or decrement operations on it. 2. When a variable appears more than once in an expression, do not use the increment or decrement operator with it.

3. Expressions and statements

An important attribute of C language is that each C expression has a value. Like q = 5*3 is also an expression, this expression as the overall value of ten, 6+ (c = 3+8) This is also an expression, and in the C language is legal, but is not recommended to use.

A statement is a complete instruction with some sort of necessary punctuation to identify it. General simple statements can be divided into 4 types: Declaration Statements, assignment statements (Assignment statements are special cases of expression statements), function statements, structured statements.

4. Type conversion

Basic rules for type conversions: 1. When the expression has char and short types, it is automatically converted to int and, if required, automatically converted to unsigned int. Under K&r C, float is automatically converted to double. 2. In any operation that contains two data types, two values are converted to a higher level in two types. 3. Types are high-to-low: long double, double, float, unsigned long long, long long, unsigned long, long, unsigned int, and int. 4. In an assignment statement, the final result of the calculation is converted to the type of the variable that will be assigned the value. When 5.char and short are passed as function arguments, they are converted to int, and float is converted to double.

5. Functions with parameters

It is important to note that the prototype is a function declaration that describes the function's return value and its parameters.

Exercises are relatively simple, no difficulty ...

To be Continued ...

C Primer Plus Reading notes the fifth chapter

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.