C language: essay 1

1. Process-oriented and object-oriented programming ideas:

Process-oriented: Process-oriented is an event-centric programming idea. It is to analyze the steps required to solve the problem, and then use functions to implement these steps step by step, and call them one by one when using them. (Meaning that if I want to do one thing, I will divide it into individual details, and then refine each detail to the extent that the CPU can accept it)

Process-oriented: (Object Oriented, OO for short) is a programming idea centered on things. (The object is to encapsulate a series of processes, and then what do you want to do is to directly manipulate this class to let him do it, it is just a encapsulation bottom layer or a process)

For example, we design a robot to let him buy food for us. If we face the process, we have to take a step by step, first raise the left foot and lower the right foot, then step on the ground and move how many degrees. This is designed for the process. Each step must be accurate, and object-oriented is different. He designed the walking action first. The left foot and right foot are designed to be in the walking class. When the object-oriented operation wants to operate it, you directly give it If he orders to go, he can go. (He just encapsulates his bottom layer or process)

2. Data type:

Figure

//符号常量
#define 标识符 常量//其中#define也是一条预处理命令(预处理命令都以#开头,称为宏定义命令)标识符一般大写

3. Variable: The amount whose value can be changed is called a variable. A variable should have a name and occupy a certain storage unit in the memory. The variable definition must be placed before the variable is used, usually at the beginning of the function body. It is necessary to distinguish between variable name and variable value as two different concepts.

Figure

int k=3;
//上述k是变量名称;3是变量值;0x0010ff是变量地址。

4. Why does char occupy 1 byte?

Because 1 byte has 8 bits, 2 to the 8th power is 256, and ASCII is exactly 256 in total.

Because there are no letters such as abc in the memory, it exists in the form of corresponding ASCII values, with only corresponding numbers such as 127 and 122. There are only numbers in the memory, not letters, and the numbers are represented by binary numbers of 1 and 0, and then slowly transform, and then slowly transform when you want to become letters.

5. Increment and decrement operators:

++i: After i increments by 1, participate in other operations.

--i: participate in other operations after i is decremented.

i++: After i participates in the operation, the value of i increases by 1.

i--: After i participates in the calculation, the value of i is decremented by 1.

i=5;
y=i++;//这里先把5赋给y,再将i的值加1,i等于6。
y=++i;//先把i的值自增1,i等于6,再把6赋值给y。

6. The basic domain of C language is introduced:

1) Expression sentence: It consists of expression plus semicolon ";".

2) Function call statement: It consists of function name, actual parameters and semicolon ";".

3) Control statements: used to control the flow of the program to achieve various structural methods of the program. They are composed of specific statement delimiters. C language has 9 kinds of control statements, which can be divided into the following 3 categories:

Type 1: Conditional judgment statement: if statement, switch statement;

Type 2: Loop execution statements: do while statement, while statement, for statement;

Type 3: Turning statement: break statement, goto statement, continue statement, return statement;

4) Compound statement: A statement composed of multiple statements enclosed in braces {} is called a compound statement;

5) Empty sentence: A sentence consisting of only a semicolon ";" is called an empty sentence. A null statement is a statement that executes nothing. In a program, a null statement can be used to empty the loop body.

7, scanf function (format input function)

scanf("format control string", address table column)

The format control string has the same effect as the printf function, but it cannot display non-format strings, that is, it cannot display prompt strings. The address of each variable is given in the address table column. The address is composed of the address operator "&" followed by the variable name.

void main()
{
   int a,b,c;
   printf("input a,b,c\n");
   scanf("%d%d%d",&a,&b,&c);
   printf("a=%d,b=%d,c=%d",a,b,c);
}

8. The break statement is dedicated to jumping out of the switch statement. The break statement has only the keyword break and no parameters. Break is to jump out of the loop. Break can also be used in statements such as for loops.

Guess you like

Origin blog.csdn.net/m0_37957160/article/details/108094150