first, the data1. What Is Data
Life is always with the data, such as weight data, blood pressure data, stock price data and so on. In our use of computer process, will be exposed to a variety of data, there are document data, image data, video data, as well as chat QQ generated text data, with thunder download file data.
2. Classification of data
The data stored in the computer can be divided into two types: static data and Dynamic Data.
(1) static data:
Concept: Static data refers to some persistent data that is typically stored on a hard disk. Hard disk storage space is generally relatively large, now ordinary computer hard disk has about 500G, so the hard disk can be stored in some relatively large files.
Storage Duration: After the computer shuts down, the data is still in, as long as you do not actively delete or the hard drive is not bad, the data will always be.
What is static data: Static data is usually stored on the hard disk in the form of files, such as documents, photos, videos, etc.
(2) Dynamic Data (temporary data)
Concept: Dynamic Data refers to temporary data that is generated dynamically during the course of a program's operation, typically stored in memory. Memory storage space is generally relatively small, now the average computer memory only about 4 G, so be careful to use memory, do not occupy too much memory space.
Storage Duration: After the computer shuts down, the temporary data is erased.
What is Dynamic Data: When you run a program (software), the entire program is loaded into memory, and as the program runs, it produces a variety of temporary data that is stored in memory. When the program stops running or the computer is forced to shut down, all temporary data generated by the program will be erased.
You might ask, why not load all the applications into the hard drive, since the storage space is so large? One of the main reasons is that the memory accesses faster than the hard disk n times.
What data does the programmer care about the most?
(3) Conversion of static and dynamic Data
Static--Dynamic
dynamic-Static
3. Size of the data
(1) Both static and dynamic data are composed of 0 and 1. How do 0 and 1 make so much data?
(2) data are size, static data will occupy the space of the hard disk, dynamic Data occupies memory space
(3) The larger the data, the more the 0 and 1 are included, bits and bytes
(4) 1 KB = 1024x768 b,1 MB = kb,1 GB = 1024x768 mb,1 TB = 1024x768 GB
A variety of data in 4.app
Data types in the 5.C language
Because of the wide variety of data in the app, C-language data is classified to facilitate the operation of data.
Second, constant1. What is a constant
Constant, which represents some fixed data
2. Classification of constants
(1) Integral type constant (int)
Includes all integers, such as 6, 27, 109, 256, 10, 0, 289, etc.
(2) floating-point constant (float\double)
Floating-point constants are divided into double and float two data types
Double: dual-precision floating point, in fact, is a decimal. such as 5.43, 2.3, 0.0 and so on (note that 0.0 is also a decimal)
FLOAT: single-precision floating-point type, also a decimal, is less accurate than a double, meaning that it can represent a smaller number of decimal places. To differentiate from double, the float type data is terminated with F, such as 5.43f, -2.3f, 0.0f. It should be noted that there is absolutely no 10f in this format, the compiler will directly error, only decimals allowed to add F.
(3) Character constant (char)
Enclose a number (0~9), English letter (A~z, a~z), or other symbol (+ 、-、!、?, etc.) in single quotation marks, which is a character constant. such as ' 6 ', ' A ', ' F ', ' + ', ' $ ' and so on.
Note: The single quotation mark can only enclose 1 characters, and cannot be Chinese characters, the following wording is wrong: ' abc ', ' 123456 ', ' Male '
(4) String constants
Enclose one or more characters in double quotation marks (""), which makes up a string constant. such as "6", "Male", "wow haha", "ABCD", "MY_CAR4", in fact printf ("Hello World"); the statement "Hello World" is a string constant.
What is the difference between 6, ' 6 ' and ' 6 ' in usage? This is not to be discussed and will be introduced later.
3. Exercises
What types of constants are the following?
10.6 19.0f 0.0 0 ' A ' "Male" "MJ" 294 ' + '
Third, variable1. What is a variable
When the value of a data needs to change or be uncertain, it should be represented by a variable. such as game points.
2. Defining variables
(1) Purpose
Before any variables can be used, they must be defined first.
The purpose of defining variables is to allocate a piece of storage space in memory to variables, which makes it easier to store data later.
If you define more than one variable, you allocate different storage space for each variable.
(2) format
Variable type variable name;
such as int num;
Variable names belong to identifiers
Variable type
Different types of variables occupy different sizes of storage space. Memory is extremely limited, allocating the appropriate storage space
The type of data that the constraint variable holds (convenient operation)
(3) Example
int Main () { int i; Char c; int A, b; return 0 ; }
3. Use of variables
(1) Assign value
To store something in a variable is to assign a value. With a semicolon after the assignment statement;
i = ten;
Note: The equals sign here is not "equal" in mathematics, but rather the assignment operator in C, which assigns the right constant 10 to the left variable i
The first assignment, which can be called "Initialize"
Two types of initialization
Define first, then initialize: int A; A = 10;
The definition is initialized at the same time: int a = 10;
(2) Modification
You can modify the value of a variable and assign it multiple times. Each assignment will overwrite the original value
i = ten;
i = ;
The last value of the variable i is 20
Use printf to output the value of one \ Multiple variables
int a = ten, C = one;
printf ("a=%d, c=%d", A, c);
Double\float\char output, some tips for formatting characters
Double height = 1.55;
char blood = ' A ';
printf ("height=%.2f, blood type is%c", height, blood);
Simple add-and-subtract operation
int a = ten + ;
Do not use when not initialized (the following wording is not recommended )
int score;
printf ("score=%d", score);
(3) Transfer of values between variables
You can assign the value of one variable to another variable
int a = 10;
int b = A;
Continuous assignment
A = b = 10;
4. Common errors
(1) The variable name is the same as int a = 10; int a = 12;
(2) The scope of the variable is not correct
Process of creating and releasing variables
code block Scope {int a = 10;}
5. Exercises
(1) The value of the integer variable A, B is exchanged. such as a=10, b=11; the value of a after Exchange is the value of 11,b is 10. Implemented in two ways:
Using third-party variables
int temp;
temp = A;
A = b;
b = temp;
Do not use third-party variables
A = b-a;
b = b-a;
A = B + A;
(2) Watch the game interface, think about how many variables need to be defined?
C Language Introduction: 04. Data types, constants, variables