Data types in the C language
- Basic data types
1) integral type (int%d)
2) character type (char%c)
3) Float type%d
①. Single-precision float (float)
②. Double-precision floating-point type (double)
- 2. Pointer type void *
3. Empty type void
4. Construction type
1) Array a[]
2) Structure struct
3) enum enum
4) Common Body Union
Note: There is no Boolean type in the C language, which means that start and pause are generally represented by 0 and 1.
Variables in the C language
(i) Definition
If the value of a data is indeterminate or often needs to be changed, it is represented by a variable.
(ii) Defining variables
Purpose: Variables must be defined before they can be used. Allocate a piece of storage space in memory to the variable to store the data later. If more than one variable is defined, multiple variables are allocated different storage spaces.
Format: Variable type + variable name;
Example: int A;char c;
Note: variable names are identifiers and require a naming convention that conforms to identifiers.
Question: Why are there many types of variables defined?
A: Different types of variables occupy a different size of storage space, because memory is extremely limited, allocating the appropriate storage space can be stored in the least space to save space.
Remember: You should define variables to save as long as you are unsure of the data. Under the 64-bit compiler, the int type occupies 4 bytes, and the total 4x8=32bit,char type is 1 bytes.
(iii) Use of variables
Initialization: There are two kinds of forms. 1.int A;a=10;2.int a=10;
Modify: You can modify the value of a variable and assign it multiple times to overwrite it.
Output: Use placeholder output variables. The various types of placeholders are as follows:
Int%d or%i
Float/double%f (output 6 bits By default, can be controlled using. 2f)
Long%ld
Long Long%lld
Char%c
String%s
Unsigned Long%zd
Basic data types and variables in C