C language Chapter 2: Data Types

1. identifier

The identifier may be a letter (A ~ Z, a ~ z ), numbers (0 to 9), underscore _ strings, and the first character must be a letter or underscore . Also note that when using the identifier of the following points:
(1) length of the identifier should not exceed 8, the first 8-bit identifier as a predetermined effective in some versions of C, when the phase of the first two identifiers 8 At the same time, it is considered the same identifier.

(2) the identifier is strictly case sensitive. E.g. Imooc and imooc are two different identifiers.

(3) the best choice for a meaningful identifier composed of English words to do "to see to know the name meaning" do not use Chinese.

(4) identifier can not be a keyword of the C language.

2. The basic data types

Basic data types

Example
Example

Example
Note: there is no string variables C language, strings can only exist in an array of characters, this will speak later.

3. format output statement

Statements formatted output, the output can also be said placeholder, various types of data is formatted according to the type and the display position designated from the computer. The advantage of this is conducive to a computer will be able to accurately type of data we want to give us.

The format is: the printf ( "Output formatter", the output item);

C language character format used:
Here Insert Picture Description
Example:
Here Insert Picture Description
The output is: Integer: 10, decimals: 7.560000, characters: C
Note: the number of specifiers to one correspondence with the number of variables, constants or expression

4. immutable constants

During program execution, the value of the amount of change does not occur is called a constant. Constant C language can be divided into direct constants and symbolic constants .
Here Insert Picture Description

In the C language, an identifier can be used to represent a constant, called symbol constant. Symbolic constants must be defined prior to use, the general form:

#define identifier constant value

Symbolic constant identifiers general practice to use uppercase letters, the variable identifier generally used to use lower case letters, be distinguished. The following is an example of using a small symbolic constant:
Here Insert Picture Description
the calculation result is: pi: 3.140000

Note: 1. The constants are immutable
   after 2. # define can no longer be defined

The automatic conversion

Here Insert Picture Description
Here Insert Picture Description
char type data conversion follows the ASCII code corresponding to an int value data
NOTE: small bytes can be automatically converted to byte large, but not large byte to byte small autochanger

6. casts

Cast is achieved by defining the type of conversion operation. Its general form:

(Data type) (expression)

Its role is the calculation result of the expression cast to type represented by type specifier, for example:
Here Insert Picture Description
output:
Here Insert Picture Description
when using cast note the following:

1, data type and must be bracketed expressions, such as the (int) (x / 2 + y) after write (int) x / 2 + y x have become converted to type int and divide by 2 and then with y Added.

2, and the conversion does not change the type of the variable value of the original data, the conversion is only temporary in this calculation.

3, the operation result of coercion does not follow the principle of rounding.

Note:

1. In the latest C standard, before the main function of the type int, not void.
2.int n = c; for the int n = c; wrong.

Source: https: //www.imooc.com/code/5120

Published 30 original articles · won praise 36 · views 703

Guess you like

Origin blog.csdn.net/qq_42745340/article/details/103483068