C language conceptual knowledge literacy (supplement and update from time to time)

program = data structure + algorithm

Program : A set of instructions that a computer can recognize and execute, each instruction causing the computer to perform a specific operation. A program consists of one or more source program files. The most fundamental function of the program is to process data, and it also needs to control the process of data processing.

Data structure : A description of the data, which data is to be specified in the program, as well as the type of these data and the organizational form of the data.

Algorithm : A description of an operation, the steps that a computer is required to perform.

The characteristics of an effective algorithm (conditions for judging that the algorithm is effective) :

  1. Finiteness: An algorithm should contain finite steps of operations, not infinite.
  2. Deterministic: Every step in the algorithm should be deterministic, not vague or ambiguous.
  3. There are zero or more inputs: Inputs refer to the necessary information that needs to be obtained from the outside world when the algorithm is executed.
  4. Has one or more outputs: The purpose of the algorithm is to find a solution, and the output is the solution.
  5. Efficiency: Each step in the algorithm should be able to be executed effectively and obtain definite results.

Structured Algorithm : An algorithmic structure consisting of three basic control structures.

There are three basic control structures of programs : sequence structure, branch structure, and loop structure.

Structured program : A structured algorithm expressed in a computer language.

Structured programming approach :

  1. top down
  2. Gradually refine
  3. modular design
  4. structured programming



language

Machine instructions : Binary codes that computers can directly recognize and accept.

Machine language : A collection of machine instructions.

Assembler : A piece of software that converts instructions in symbolic language (assembly language) into machine instructions.

Compiler (compiler) : A software that converts a program written in a high-level language (source program) into a program of machine instructions (object program).

Compilation : The process of generating an object program from a source program using a compiler.

Executable program : After the program is compiled, it is processed (connection editor) to generate an object program that can be executed by the computer.

Program and source program : A program consists of one or more source program files. A source program file consists of one or more functions and other relevant content (such as instructions, data declarations and definitions, etc.). A source program file is a compilation unit. When compiling a program, it is compiled in units of source program files, not in units of functions.




function

Function : A function is a function. Each function is used to achieve a specific function. The name of the function should reflect the function it represents. A function is the main component of a C program and a subroutine of the C language. The main function is also one of the functions.

The function of the function declaration : the function of the function declaration is to inform the compilation system of the information about the function (function name, function type, number and type of function parameters), so that when a function call is encountered, the compilation system can correctly identify the function and check Is the call legal.

Actual parameter and formal parameter : When the function is called, the actual parameter variable transfers its value to the formal parameter variable (value transfer). The actual parameter and the formal parameter occupy different storage units in memory. After the function call ends, the formal parameter is stored Space is freed. Due to the characteristics of one-way value transfer, the change of the value of the formal parameter cannot cause the value of the actual parameter to change accordingly.




sentence

Statement : A statement is the most basic execution unit of a program, and the function of a program is realized by executing a series of statements.

Identifier : Some valid character sequences used to name variables, symbolic constant names, functions, data types, etc. Simply put, an identifier is the name of an object. Consists of letters, numbers, and underscores, where the first character must be a letter or an underscore.

if-else statement : C language only has if-else branch statement, but no if-(else if)-else form. Generally, the else if we use is essentially an if nested in the else. The if is at the same level as the else immediately following it.




data

Constant : A quantity whose value cannot be changed while the program is running.

Variable : A quantity whose value can change while the program is running.

Loop control variable : By changing and judging the value of a variable to control the execution of the loop, such a variable is called a loop control variable.

Constant variable : When defining a variable, add a keyword const in front, and its value cannot be changed during the variable's existence.

Symbolic constant : Use the #define directive to specify a symbolic name to represent a constant, called a symbolic constant. After precompilation, symbolic constants will all become literal constants.

Global declaration : the data declaration made outside the function.

Global Variables : Variables declared outside a function are called global variables. Valid within the scope of the entire source program file. By convention, the first letter of a global variable name is capitalized. If the global variable is not assigned an initial value, the system automatically assigns a value of 0.

Local variable : The variable declared in the function is a local variable, which is only valid within the scope of the function. If the local variable is not assigned an initial value, an error will be reported.

Scope : If a variable is valid within the scope of a certain file or function, that scope is called the scope of the variable.

Data type : The so-called type refers to the arrangement of the data allocation storage unit, including the length of the storage unit (how many bytes) and the storage form of the data. Different types allocate different lengths and storage forms.

Array : A collection of ordered data, each element in the array belongs to the same data type. The array name represents the address of the first element of the array, or the starting address of the array.

Character array : C language has no string type, and there is no string variable. Strings are stored in character arrays. Arrays used to store character data are character arrays. Since character data is stored in integer form (ASCII code), integer arrays can also be used to store character data. Although this is legal, it will waste storage space.

String : A string is not a variable, but a constant. In the C language, there are only character variables, not string variables.

Structure : A combined data structure composed of different types of data.

Declaration and definition : A declaration that creates a storage space is called a definition, and a declaration that does not need to create a storage space is called a declaration (or reference). The function of the so-called statement is to indicate that the variable is a variable that has been defined elsewhere, and it is only a "declaration" made to expand the scope of the variable.




operation

Operators : Operators represent operations on data objects of various data types.

Expressions : Meaningful combinations of operators and operands (which can be constants, functions, variables, etc.) form expressions.

Arithmetic expression : A formula that uses arithmetic operators and parentheses to connect the operands (operands) and conforms to the grammar rules of the programming language is called an arithmetic expression.

Relational expression : A formula that connects two values ​​or numerical expressions with relational operators is called a relational expression. The value of a relational expression is a logical value, and there are only two results, namely "true" and "false". In the logical operation of C language, the value 1 represents true, and the value 0 represents false.

Logical expression : A formula that connects relational expressions or other logical quantities with logical operators is a logical expression. Logical expressions have only two results, namely "true" and "false". In the logical operation of C language, the value 1 represents true, and the value 0 represents false.

Lvalue : Lvalue means that it can appear on the left side of the assignment operator, and its value can be changed. Not any form of data can be used as an lvalue, and an lvalue should be a storage space and can be assigned.

Rvalue : An expression that can appear on the right side of an assignment operator is called an rvalue. Lvalues ​​can also appear on the right side of assignment operators, so any lvalue can be used as an rvalue.

Relational operators and their order of precedence :

  1. <, <=, >, >= have the same precedence, and == has the same precedence as !=. But the first four have higher priority than the last two.
  2. Relational operators have lower precedence than arithmetic operators ( +, -, *, /, % ).
  3. Relational operators have higher precedence than assignment operators ( = ).

Logical operators and their order of precedence :

  1. ! (not) is greater than && (and) is greater than || (or).
  2. && and || are lower than relational operators, and ! is higher than arithmetic operators.



pointer

  1. A pointer is an address

    • A pointer variable is a variable that stores an address. It can also be said that a pointer variable is a variable that stores a pointer.
    • The value of a pointer variable is an address, it can also be said that the value of a pointer variable is a pointer.
    • A pointer variable can also be called an address variable, and its value is an address.
    • & is an address operator, &a is the address of a, and it can also be said that & is a pointer operator. &a is a pointer to variable a (that is, a pointer to variable a).
    • The array name is an address, which is the address of the first element of the array; it can also be said that the array name is a pointer, which is the pointer of the first element of the array.
    • The function name is a pointer (pointing to the first byte of the function code area), it can also be said that the function name is an address (the address of the first byte of the function code area).
    • If the actual parameter of the function is an array name, what is passed to the formal parameter is an address. It can also be said that what is passed to the formal parameter is a pointer.
  2. pointers are of type

    All data in the C language is typed, and the address is also typed. It is stored according to the storage method of pointer data, which is different from the storage method of integer or floating point.

    An address type (pointer type) data contains three pieces of information:

    • A plain address representing a memory number
    • its own type, the pointer type
    • What type of data is stored in the storage unit identified by it, that is, the base type.

    A void* pointer is a special pointer that does not point to any type of data. If you need to use this address to point to a certain type of data, you should perform type conversion on the address first. (manual explicit conversion, system implicit conversion)

  3. pointers and pointer variables

    A pointer is an address, and a pointer variable is a variable used to store an address, and the value of a pointer variable is an address.

  4. what is pointing to

    An address means pointing to, because an address can be used to find the object with that address. For pointer variables, the address of whose address is stored in the pointer variable is said to be pointed to by the pointer variable. (Premise: Only data with the same base type as the pointer variable can have its address stored in the corresponding pointer variable.)

  5. Inductive comparison of pointer variables

    Variable definitions type representation meaning
    int i; int Define an integer variable i
    int* p; int* Define p as a pointer variable pointing to integer data
    int a[5]; int [5] Define an integer array a with 5 elements
    int* p[5]; int* [5] Define the pointer array p, which consists of 5 pointer elements pointing to integer data
    int(*p)[5]; int(*)[5] p is a pointer variable pointing to a one-dimensional array containing 5 elements
    int f( ); int( ) f is a function that returns an integer function value
    int* p( ); int* ( ) p is a function that returns a pointer to integer data
    int(*p)( ); int(*)( ) p is a pointer to a function that returns an integer value
    int** p; int** p is a pointer variable that points to a pointer variable pointing to integer data
    void* p; void* p is a pointer variable, the base type is void (empty type), and does not point to a specific object



Some links:

C language data type conversion rules (implicit conversion + explicit conversion)

Some Precautions for Using C Language Strings

Storage method and lifetime of variables in C language

Some Notes on Custom Functions in C Language

Some Error-prone Points of C Language Pointers

Guess you like

Origin blog.csdn.net/jiang1126/article/details/125395627
Recommended