C language summary, C Language
Summary of the 11-day course (only for summary. For details, refer to the previous section)
I. Ordered Structure
Code structure executed from top to bottom
When a computer executes a program, it is compiled into binary files, which are further divided
Binary: for example, 101001001 is a binary number.
Octal: for example, 023767 is an octal digit. The preceding 0 indicates an octal digit.
Decimal: 10, 33, 22 is a decimal number
Hexadecimal: 0x28AD represents a hexadecimal number, and 0x represents a hexadecimal number.
OPERATOR:
Int a = 10, B = 20;
Arithmetic Operators
+: Addition operation example: a + B = 20
-: Subtraction a-B =-10
*: Multiplication a * B = 200
/: Division operation a/B = 0 (integer division results take the integer part, not after the decimal point) any number except 10 is equivalent to removing a single digit
%: Remainder operation a % B = 10
Comparison operator (boolean type)
>: Whether the comparison is greater than a> B false
<: Whether the comparison is less than a <B true
=: Whether the comparison is equal to a = B false
>=: Greater than or equal to a> = B false
<=: Less than or equal to a <= B false
% =: Returns the remainder equal
! =: Not equal
Logical operators (boolean type)
&: And when condition 1 & condition 2 both meet condition 1 and condition 2, the result is true (one is false, two are true)
|: Or condition 1 | condition 2 is true when one condition is met (true or false)
! : Not required! Returns the Boolean value of a condition.
Constants, variables, and expressions
Constant: cannot be changed in the program
Variable: can be changed in the program
Expression: A sub-expression that combines constants, variables, and operators.
Ii. Select Structure
Optional Execution Code
If (conditional expression ){
Statement
}
If (conditional expression 1 ){
Statement 1
} Else if (condition expression 2 ){
Statement 2
}...
Switch (){
Case1 :{
Statement 1;
Break;
}
Case2 :{
Statement 2;
Break;
}
...
Default :{
Statement;
Break;
}
}
Iii. Loop Structure
When a loop condition is met, the structure of a code (loop body) is repeatedly executed.
For Loop
For (Conditional Variable initialization; conditional expression; conditional variable increment ){
Statement (loop body)
}
While Loop
Initial Value of the condition variable;
While (conditional expression ){
Statement (loop body );
Conditional Variable increment;
}
Do... while loop (basically not used)
Do (statement (loop body )){
Conditional Variable Increment
} While (conditional expression)
Iv. arrays and struct
One-bit array, two-dimensional array, multi-dimensional array, character array, String Array
Must be composed of elements of the same data type
Two-dimensional array sorting (Bubble Sorting)
Int arr [5] = {2, 6, 3, 7, 5}; // count is the size of the array.
For (int I = 0; I <count-1; I ++ ){
For (int j = 0; j <count-1-I; j ++ ){
If (arr [j]> arr [j + 1]) {
Int temp = arr [j];
Arr [j] = arr [j + 1];
Arr [j + 1] = temp;
}
}
}
Struct: it can store multiple types of elements.
Struct student {
Struct variable 1;
Struct variable 2;
...
};
When we define a struct, we use typedef to redefine a new name for the struct.
Typedef struct {
Struct variable 1;
Struct variable 2;
...
} Student; // give Student a new name to the struct.
In addition, define (macro definition) and enum (enumeration) are also struct
Struct array: used to store struct Variables
Example:
Typedef struct {
Char name [20];
Int age;
Float score;
} Student;
Student stu1 = {"xiaoming", 20, 80 };
Student stu2 = {"xiaohong", 19, 90 };
Student stu [] = {stu1, stuff };
Printf ("% s % d %. 2f ", stu [1]. name, stu [1]. age, stu [1]. score) // Add (. variable name)
5. Functions (For details, refer to the function article)
Encapsulate code blocks that implement a function
For example, formatted input and output functions
Printf ("") Output Function
Scanf ("", & variable name) Input Function
Such functions provided by the system are called system functions, and the functions compiled by the compiler themselves are called custom functions.
For example:
Int sum (int a, int B ){
Return a + B;
}
This is a user-defined summation function.
Functions are divided:
No parameter no return value: void (){
Printf ("hello ");
}
No parameter has returned value: int B (){
Return 3;
}
There are parameters and no return value: void c (int x ){
Printf ("hui zi ");
}
Parameters return values: int d (int y ){
Return y;
}
Function writing steps:
1: function declaration
2: Writing Functions
3: function call
6. pointer (see the first two articles for details)
A pointer is an address that points to a variable address.
Function pointers and pointer Functions
A function pointer is a pointer pointing to a function.
A pointer function is a function, and the return value is a pointer.
Struct pointer
Pointer to struct
7. dynamic memory Division (see the first two articles for details)
Stack zone: the memory address is the highest, and all declared variables and so on are here. The stack cannot be released automatically after the first release.
Heap zone: The maximum memory space. Manual application and release are required.
Global zone (static zone): stores global variables and adds static variables before any variables. The variables are placed in the global zone.
Constant Area: stores constants.
Code zone: the zone where CPU commands generated by code compilation are stored