当前位置:网站首页>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 )

  1. C Language foundation ( Loop statement )

  2. for loop

  3. 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 .

  4. 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 .

  5. for Nesting format
    for( expression 1; expression 2; expression 3)
    {
    for( expression 1; expression 2; expression 3)
    {
    The loop body ;
    }
    }

  6. while loop

  7. 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 .

  8. 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 .

  9. goto loop

  10. Format
    loop:
    Code segment ;
    if( expression )
    goto loop;

  11. Execution order :
    Execute code snippets , Determine if the expression holds , Set up jump to loop Continue to execute the code snippet .

  12. Loop control statement :break;continue;return

  13. break: Out of the loop ( End of cycle );

  14. continue: End this cycle , So let's go to the next loop .

  15. return: End function .Main Function , Not normally executed main Function content , It is customary to write :return -1;

  16. Array

  17. Concept :
    A collection of data consisting of one or more data types , Each data that makes up an array is called an element .

  18. characteristic
    Same data type , Memory space is continuous .

  19. One dimensional array

  20. Concept : An array with only one subscript .

  21. Define format :
    [ Storage type ] data type Array name [ Subscript ];
    Subscript : Number of elements .

  22. Element access : Array name [ Subscript ].
    Value of subscript : from 0 Start , Element number = Subscript number -1;

  23. 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 .

  24. sizeof( Array name ): Calculate the space occupied by the array .

  25. Be careful :

  26. 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 .

  27. Once the array is defined, the memory space opened up has been determined , Subscript cannot be random value or unknown quantity when defining .

  28. Cross border access to data , Don't complain , Pay attention to the problem of crossing the boundary when using .

  29. Sort : Bubbling 、 choice

  30. 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 .

  31. Two dimensional array

  32. Concept : An array with two subscripts .

  33. 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 .

  34. Traversing a two-dimensional array : Nested loop

  35. Initialization of local two-dimensional array

  36. Not initialized when defining , The initial value is a random value , Next, assign values one by one .

  37. Partial initialization during definition , Is initialized to 0.

  38. Initialize all when defining , Line subscripts can be omitted .

  39. 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 .

  40. 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.

  41. 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.

  42. String operation function

  43. 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 .

  44. 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).

  45. Zero clearing function :memset; bzero

  46. 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.

  47. bzero(s,n)
    a) function : Zero clearing .
    b) Parameters :s: Clear the first address of the content ;n: Empty bytes .
    c) Return value : nothing .

  48. The pointer

  49. 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 .

  50. 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 .

  51. Pointers are used in combination with arrays

  52. 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 operation

  53. Indirect access to one-dimensional arrays
    Address :p+i; &p[i];
    Content :*(p+i); p[i].

  54. The operation of the pointer

  55. 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 pointers

  56. Relationship between operation

< >= <= != ==
The large address is larger than the small address .

  1. The assignment operation :
    = += -=
    It is meaningless to operate between pointers of different data types .
  2. The secondary pointer
  3. Concept : Save the address of the meter and pointer .
  4. 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.
  5. Const Constant quantity
  6. 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 .
  7. 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 .
  8. void Empty type
    No, void Variable of type , It can be used void Modify a pointer , Decorate a function or as a function parameter .
  9. 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 .
  10. Strong go
  11. Strong conversion of data type
    Format : Variable =( data type ) value ;
    Generally, it is implicit strong rotation , When calculating, turn low precision into high precision .
  12. Strong rotation of pointer type
    Format : Pointer to the variable =( data type *) Address values .
  13. 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 .
  14. function
    Three elements of the function : function 、 Parameters 、 Return value .
  15. Definition : Encapsulate the code module of a specific function into a function ( Interface ).
  16. 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 .
  17. Function call : Function name ( Actual parameters )
  18. 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 .
  19. 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 .
  20. Arguments to functions
  21. Value passed
    Copy a copy of the value and pass it to other functions , Change the copied content , The original content has not changed .
  22. Address delivery
    Pass the address of the variable to other functions , The meta content can be modified through the address .
  23. Array passing
    The essence is also address passing , Passing is the first address of the array .
  24. Command line arguments
    int main(int argc,const char *argv[])
  25. argc: Number of command line arguments
  26. argv: Save command line parameter content , The first address of each parameter is saved .
  27. string Family of functions
  28. 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
  29. 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’;
  30. 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 .
  31. 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 .
  32. 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.
原网站

版权声明
本文为[xiq1212]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/204/202207230539252115.html