当前位置:网站首页>Embedded from entry to mastery (buried) - sharing of ultra detailed knowledge points 2
Embedded from entry to mastery (buried) - sharing of ultra detailed knowledge points 2
2022-07-23 12:33:00 【xiq1212】
Linux C From entry to mastery ( The grave )
C Language foundation ( Loop statement )
for loop
Format :
For( expression 1; Expression two ; expression 3)
{
The loop body ;
}
expression 1: Initial value of Fu ;
expression 2: Termination conditions ;
expression 3: Appreciation or impairment .
Be careful :
a) No initial value expression , It can be written in for Upper edge of loop ;
b) There is no expression 2, A cycle is an endless cycle , There is no expression 3 It's also a dead cycle , But expression 3 It can be written at the end of the loop .
c) for(;;): It means a dead cycle .Execution order
Execute expression first 1, Then judge the expression 2 Is it true , Set up the execution loop , Then execute the expression 3, Then judge the expression 2 Is it true , Then continue to execute the circulatory body , Then execute the expression 3…… Until the expression 2 Don't set up , The loop ends .for Nesting format
for( expression 1; expression 2; expression 3)
{
for( expression 1; expression 2; expression 3)
{
The loop body ;
}
}while loop
Format 1
While( expression )
{
The loop body ;
}
Execution order : Determine if the expression holds , Set up the execution loop , Then judge whether the expression is true , Set up the execution loop ,…… Until the expression doesn't hold , The loop ends .
Be careful :while(1)= Dead cycle .Format two :do……while
do{
The loop body ;
}while( expression );
Execution order : First, execute the loop body , Then judge whether it is true , Set up the continuous execution loop , Not set up to end the cycle .goto loop
Format
loop:
Code segment ;
if( expression )
goto loop;Execution order :
Execute code snippets , Determine if the expression holds , Set up jump to loop Continue to execute the code snippet .Loop control statement :break;continue;return
break: Out of the loop ( End of cycle );
continue: End this cycle , So let's go to the next loop .
return: End function .Main Function , Not normally executed main Function content , It is customary to write :return -1;
Array
Concept :
A collection of data consisting of one or more data types , Each data that makes up an array is called an element .characteristic
Same data type , Memory space is continuous .One dimensional array
Concept : An array with only one subscript .
Define format :
[ Storage type ] data type Array name [ Subscript ];
Subscript : Number of elements .Element access : Array name [ Subscript ].
Value of subscript : from 0 Start , Element number = Subscript number -1;initialization
a) Not initialized when defining
The initial value is a random value . Next, you need to assign initial values one by one , Elements without initial values are still random values .
b) Partial initialization during definition
Uninitialized element value is 0.
c) Definition time , All initialization
Subscripts can be omitted .sizeof( Array name ): Calculate the space occupied by the array .
Be careful :
If the subscript is omitted during development , How many elements correspond to how many openings are initialized . If the subscript is not omitted , How many subscript values open up how many element spaces , You can only initialize the number of elements as the subscript value .
Once the array is defined, the memory space opened up has been determined , Subscript cannot be random value or unknown quantity when defining .
Cross border access to data , Don't complain , Pay attention to the problem of crossing the boundary when using .
Sort : Bubbling 、 choice
Bubble sort : Subscript to be 0 And the subscript is 1, Move the small number back , Then subscript 1 And the subscript is 2 Comparison , Small backward , Until you put the smallest one last . Again , Put the second smallest number in the penultimate position . Sort by analogy .
Two dimensional array
Concept : An array with two subscripts .
Format :
[ Storage type ] data type Array name [ Line subscript ][ Column subscript ]
Access element content : Array name [ That's ok ][ Column ]; The subscript value is from 0 Start .Traversing a two-dimensional array : Nested loop
Initialization of local two-dimensional array
Not initialized when defining , The initial value is a random value , Next, assign values one by one .
Partial initialization during definition , Is initialized to 0.
Initialize all when defining , Line subscripts can be omitted .
The address of the array
In the computer, the unit is bytes , Each byte has its own address number . If the space is defined, save the address number ,32 The address number for the operating system is 32 position , It needs to be opened up 4byte,64 Bit the address number of the operating system 64 position , It needs to be opened up 8byte.
Array memory space is continuous , Get the first element address , You can add 1 Get the address of the second element in the form of .One dimensional array
The array name of one-dimensional array is one-dimensional array d Forehead address , Is the address of the first element , It's an address constant , Once an array is defined , The first address is determined , Can't change .
a) Address +1: What you get is the address of the next element .
b) Add... Before the address *, Indicates the content of the address .
c) Direct access to element content :st[i] *(st+i);
d) Directly access the element address :&st[i] st+i.Two dimensional array
The array name of the two-dimensional array represents the address of the first row of the two-dimensional array , It's a line address , Is the address constant . Array name plus 1, Indicates the address of the next line .
a) The second use of : Add , Reduce row address to column address .
b) Two dimensional arrays can be regarded as multiple one-dimensional arrays , The array name of each one-dimensional array is :st[0]、st[1]、st[2]……st[n-1].
c) Array name [ Line subscript ]: Represents the address of the first element of each line .
d) Direct access to element content :st[i][j]; ((st+i)+j); *(st[i]+j)
e) Directly access the element address :&st[i][j]; *(st+i)+j; st[i]+j.String operation function
gets Get the string from the terminal
a) function : Get the string from the terminal , And will automatically add ‘\0’;
b) Parameters : Get the first address of string storage .
c) Return value : Successful return to get the address where the string is stored
Failure to return NULL.
Be careful : How much does the terminal input ,gets Take how much , There is no boundary crossing problem of half detection array , To use less .puts Output string to terminal
a) function : Output the string to the terminal display .
b) Parameters : The first address of the output string .
c) Return value : success : Number of output characters ; Failure :EOF(-1).Zero clearing function :memset; bzero
memset(s,c,n):
a) function : Zero clearing .
b) Parameters :s: Clear the first address of the content ;c:0;n: Empty bytes .
c) Return value : success : Clear the first address of the content s; Failure :NULL.bzero(s,n)
a) function : Zero clearing .
b) Parameters :s: Clear the first address of the content ;n: Empty bytes .
c) Return value : nothing .The pointer
First level pointer
a) The pointer : It's the address .
b) Define format :[ Storage type ] data type * Pointer variable name
Be careful : What kind of variable , You need to define the pointer of the corresponding type to save the address of the variable , Can access variables indirectly through pointers .Three uses of
a) Add before address : Fetch address content .
b) Add... Before the line address *: Demote to column address ( Element address ).
c) Data type followed by *: Represents the definition of a pointer variable of the corresponding type .Pointers are used in combination with arrays
Pointers and one-dimensional arrays :
Save the first address of one-dimensional array through pointer , Let pointer variables instead of one-dimensional array names indirectly access one-dimensional arrays .
The array name is the address constant . Pointer variables are variables , Changes can occur during program operationIndirect access to one-dimensional arrays
Address :p+i; &p[i];
Content :*(p+i); p[i].The operation of the pointer
Arithmetic operation
a) + :p+n The pointer moves in the direction of the larger address n Data
b) –:p-n The pointer moves in the direction of small address n Data
c) ++ :p++ The pointer moves a number in the direction of the larger address
d) – :p— The pointer moves in the direction of small address 1 Data
e) - :p-q The number of data elements separated between two pointersRelationship between operation
< >= <= != ==
The large address is larger than the small address .
- The assignment operation :
= += -=
It is meaningless to operate between pointers of different data types . - The secondary pointer
- Concept : Save the address of the meter and pointer .
- Format :[ Storage type ] data type ** Pointer variable name ;
Be careful : As long as it's a pointer , What you save is the address number ,32 Bit operating system pointer is opened 4byte. - Const Constant quantity
- const Modifying variables
const Modifying variables , The value of a variable cannot be modified by its name , But you can define a pointer to a variable , Access the address content through the pointer to modify the value . - const Modify a pointer
a) const int *p
The pointer can be modified , What the pointer points to cannot be modified by the pointer .
b) int * const p
The pointer to cannot be modified , The content pointed to by the pointer can be modified by the pointer .
Be careful : Because the pointer cannot be modified , Only one point can be assigned at the time of definition .
c) const int * const p
The pointer to cannot be modified , The content pointed to by the pointer cannot be modified by the pointer . - void Empty type
No, void Variable of type , It can be used void Modify a pointer , Decorate a function or as a function parameter . - void Modify a pointer
void* A pointer to a type can match an address of any type , However, it needs to be forcibly converted to the corresponding address type . - Strong go
- Strong conversion of data type
Format : Variable =( data type ) value ;
Generally, it is implicit strong rotation , When calculating, turn low precision into high precision . - Strong rotation of pointer type
Format : Pointer to the variable =( data type *) Address values . - Large and small end
a) Big end storage : Low address stores high byte content , High address stores low byte content .
b) Small end storage : Low address stores low byte content , High address stores high byte content . - function
Three elements of the function : function 、 Parameters 、 Return value . - Definition : Encapsulate the code module of a specific function into a function ( Interface ).
- Define format :
[ Storage type ] data type Function name ( Shape parameter )
{
The body of the function ;
Return Constants or variables or expressions ;
}
Be careful :
a) Returned constant or variable or expression , The data type must be consistent with the function data type . If there is no return , The function type is defined as void type , There is no return sentence .
b) The defined function needs to be directly or indirectly main Function call can realize function .
c) If defined function does not need to pass parameters , The formal parameters of the function prototype are written as void. If not void, Pass the actual argument value , No mistake. , But this argument value will take up resource space , If you use this space later, there will be errors , It's easy to find the cause of the error . - Function call : Function name ( Actual parameters )
- Function declaration :[ Storage type ] data type Function name ( Shape parameter );
a) The function is declared in main Upper edge of function , Declaration can omit formal parameter variable name .
b) If the function prototype is defined in main Upper edge of function , The statement may not be written . - The difference between formal parameter and argument
a) Shape parameter : Formal parameters are formal parameter variables defined when defining functions , Is a formally existing value , Function calls will open up memory space .
b) Actual parameters : The argument is the value passed when calling the function , Is the actual value , There is memory space for development and storage . - Arguments to functions
- Value passed
Copy a copy of the value and pass it to other functions , Change the copied content , The original content has not changed . - Address delivery
Pass the address of the variable to other functions , The meta content can be modified through the address . - Array passing
The essence is also address passing , Passing is the first address of the array . - Command line arguments
int main(int argc,const char *argv[]) - argc: Number of command line arguments
- argv: Save command line parameter content , The first address of each parameter is saved .
- string Family of functions
- strlen(char *s)
a) function : Calculate the length of the string , barring ‘\0’;
b) Parameters :s: The first address of the string to be calculated ;
c) Return value : Length of string - strlrn and sizeof The difference between
a) strlen Is the function ,sizeof Is the key word .
b) strlen Is to calculate the actual number and length of characters in the string , barring ‘\0’;
c) sizeof It is used to calculate the memory space occupied , Include ‘\0’; - strcpy(char *dest,char *src)
a) function : Copy the string
b) Parameters :dest: The storage location of the copied string ;src: The string to copy .
c) Return value : The first address of the copied string . - strcat(char *dest,char *src)
a) function : Realize string splicing , take dest After ‘\0’ Remove and splice .
b) Parameters :dest: The storage location of the string to be spliced ;src: The string to be spliced .
c) Return value : The first address of the concatenated string . - strcmp(char *s1,char *s2)
a) function : Compare the size of two strings , Compare by character , Compare characters ASCII code .
b) Parameters : The first address of two strings .
c) Return value :s1>s2 Return positive number ;s1<s2 Return negative ;s1=s2 return 0.
边栏推荐
- 利用google or-tools 求解逻辑难题:斑马问题
- 高等代数知识结构
- The online seminar on how to help data scientists improve data insight was held on June 8
- 使用PyOD来进行异常值检测
- 单片机学习笔记5--STM32时钟系统(基于百问网STM32F103系列教程)
- [AUTOSAR CP general 1. how to read AUTOSAR official documents]
- Data analysis of time series (I): main components
- NLP natural language processing - Introduction to machine learning and natural language processing (2)
- Uni native plug-in development -- Youmeng one click login
- ARM架构与编程1--LED闪烁(基于百问网ARM架构与编程教程视频)
猜你喜欢

高等代数100道题及答案解析

NVIDIA NVIDIA released H100 GPU, and the water-cooled server is adapted on the road

【基于UDS服务的BootLoader架构和刷写流程】

NLP natural language processing - Introduction to machine learning and natural language processing (2)

How to develop the computing power and AI intelligent chips in the data center of "digital computing in the East and digital computing in the west"?

Questions and answers of basic principles of steel structure

利用google or-tools 求解逻辑难题:斑马问题

Tips for using textviewdidchange of uitextview

ARM架构与编程1--LED闪烁(基于百问网ARM架构与编程教程视频)

5.4 Pyinstaller库安装与使用
随机推荐
Baidu Shen Shuo: focus on the scene, deeply cultivate the industry, and bring practical results to enterprise Digitalization
【AUTOSAR CanDrive 1.学习CanDrive的功能和结构】
NLP natural language processing - Introduction to machine learning and natural language processing (I)
ARM架构与编程7--异常与中断(基于百问网ARM架构与编程教程视频)
Lvgl8.1 version notes
【AUTOSAR COM 1.通信协议栈介绍】
C语言小项目——学生成绩管理系统
Gartner research: how is China's digital development compared with the world level? Can high-performance computing dominate?
Installation and use of APP automated testing tool appium
Data mining scenario - false invoice
谈谈转动惯量
How can knowledge map, map data platform and map technology help the rapid development of retail industry
Using or tools to solve the path planning problem with capacity constraints (CVRP)
高分子物理名词解释归纳
对字符串函数的使用和理解(2)
Object class
高电压技术复习资料
时间序列的数据分析(二):数据趋势的计算
The green data center "counting from the east to the west" was fully launched
Using Google or tools to solve logical problems: Zebra problem