Summary of the 11-day lesson (only for summary, see above for details)
First, sequential structure
The code structure that executes from the top down
When the computer executes the program, it is compiled into a binary file, and the computer is divided into
Binary: For example, 101001001 is a binary number
Octal: For example 023767 is an octal number, the preceding 0 represents this is an octal number
Decimal: 10,33,22 is a decimal number
Hex: 0X28AD represents a hexadecimal number, and 0x means it's a hexadecimal number.
Operator:
int a = 10,b = 20;
Arithmetic operators
+: Example of addition operation: A + b = 20
-: Subtraction Operation A-B =-10
*: Multiply operation A * b = 200
/: Division operation A/b = 0 (integer division result takes integer part, not after decimal point)
Any number except 10 is equivalent to removing bits
%: Take-up operation a% B = 10
Comparison operators (for Boolean types)
>: Compare if greater than a > B false
<: compare if less than a < b true
= = : compare equals a = = b False
>=: greater than or equal to a >= b false
<=: less than equals a < = B false
%=: take the remainder equals
! = : Not equal to
Logical operators (Boolean type)
&&: and condition 1 && Condition 2 satisfies both conditions 1 and 2 o'clock, the result is true (one false, two true)
| | : or condition 1 | | Condition 2 satisfies a condition The result is true (one true, two fake is false)
! : Non -conditional! Reverse the Boolean value of a condition
constants, variables, expressions
Constants: cannot be changed in the program
Variables: Can be changed in the program
Expressions: Formulas that are combined by constants, variables, and operators
II. Choice of structure
Selective code of execution
if (conditional expression) {
Statement
}
if (conditional expression 1) {
Statement 1
}else if (conditional expression 2) {
Statement 2
}. . .
Switch () {
case1:{
Statement 1;
Break
}
case2:{
Statement 2;
Break
}
. . .
default:{
Statement
Break
}
}
Third, the cycle structure
When a loop condition is met, the structure of a piece of code (the loop body) is executed repeatedly
For loop
for (conditional variable initialization; conditional expression; condition variable increment) {
Statement (loop body)
}
While loop
The initial value of the condition variable;
while (conditional expression) {
Statement (loop body);
conditional variable increment;
}
Do ... while loop (basic not used)
Do (statement (loop body)) {
Conditional variable Increment
}while (conditional expression)
Iv. arrays, structures
An array, a two-dimensional array, a multidimensional array, a character array, an array of strings
Must be composed of the same data type elements
Two-dimensional array sorting (bubbling sort)
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: Can hold multiple types of elements
struct Student {
struct variable 1;
struct variable 2;
. . .
};
In general, when we define a struct, we use typedef to redefine a new name directly to the struct body.
typedef struct {
struct variable 1;
struct variable 2;
. . .
} Student; //Give the struct a new name student
Another define (macro definition), enum (enum) is also a struct
struct arrays: Storing structure 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)//print array elements, you need to append (. Variable name)
V. Functions (see the function in detail)
Encapsulation of a code block that implements a function
For example: formatted input, output function
printf ("") output function
scanf ("", & variable name) input function
Functions such as this system-provided function are called system functions, and functions written by the compiler themselves are called custom functions.
For example:
int sum (int a,int b) {
return a + B;
}
This is a custom summation function.
Functions are divided into:
No parameter no return value: void A () {
printf ("Hello");
}
No parameter has return value:int B () {
return 3;
}
No return value with parameter:void C (int x) {
printf ("Hui Zi");
}
There are parameters with return values: int d (int y) {
return y;
}
Steps to write the function:
1: Declaration of functions
2: Writing of functions
3: Call to function
Vi. pointers (see the top two articles for more information)
The pointer is the address, pointing to a variable address
function pointers, pointer functions
A function pointer is a pointer to a function
The pointer function is a function, and the return value is a pointer
struct-Body pointer
Pointers to struct bodies
Seven, dynamic memory Division (see the top two articles for more information)
Stack area: Highest memory address, declared variables and the like are in this, advanced out, not automatically released
Heap Area: The largest memory space, need to manually request, manually release
Global Zone (Static zone): Holds global variables, adds static to any variable, and puts the variable into the global zone
Constant area: Storing constants
Code area: The area where the CPU instructions generated by code compilation are stored
C-Language summary