First, the data
Picture text and so on are data, stored in the computer with 0 and 1.
(i) Classification
Data is divided into static data and dynamic Data.
①. Static data: Some permanent data, usually stored in the hard disk, as long as the hard disk is not bad data are present. Usually stored in the form of files on the hard disk, the computer shutdown after the restart still exists.
②. Dynamic Data: During the process of running the program, the dynamically generated temporary data, generally stored in memory, memory storage space is generally small, the computer shuts down after the data will be erased. The temporary data will be erased if the software or computer shuts down.
③. Static data and dynamic data can be converted.
④. Note: Why not store Dynamic data on the hard drive? Because the speed of direct access to memory is faster. The software is installed on the hard disk and runs in memory. Programmers should be more concerned with memory data.
(ii) Data size
①. All data is made up of 0 and 1.
②. Data is size, static data takes up hard disk space, and dynamic Data accounts for memory space.
③. The larger the data, the more 0 and 1 are included,
④. The units in which data is stored are bits and bytes. A 1 or 0 is a bit, that is, 1bit.
⑤. In a computer, data is stored in bytes. 1 bytes = 8 bits (1byte=8bit).
⑥. 1tb=1024gb,1gb=1024mb,1mb=1024kb,1kb=1024b.
(iii) Types of data 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.
Second, constant
(i) Definition
Constants represent fixed data.
(ii) classification
①. Integral type constants such as 6,27,-299
②. Floating-point constants such as 5.43,-2.3,5.67f
③. Character constants such as ' 6 ', ' A ', ' F ' (not Chinese as ' male ')
④. String constants such as "6", "Male", "NANABC"
Third, variable
(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
(iv) Use of variables note
Scope of a variable: the line from which the variable is defined, until the end of the code block.
Return; exit the function to clear the in-memory data.
Recommendation: Use rectangular boxes and Excel to analyze memory.
The role of code block {}: It can be used to improve performance and instantly reclaim variables that are no longer used.
(v) Practice
Exercise: Use two methods to exchange the values of two variables.
The first type:
First Kind
The second type:
The second kind
Li Hongqiang-C language 9-c language data, variables and constants