Chapter 2 C language basics
1. Concept
C is a very small Kernel Language and contains very few hardware-related elements. It can be said that C is highly portable. For example, the C language does not provide statements related to file operations or dynamic memory management. In fact, it does not even directly provide console output and input statements. The C language uses an Extended Standard C-Linked Library to provide a variety of functions required for a variety of programming purposes.
Because C is specially developed as "system programming", one of its main purposes at present is to write "embedded system programs", which won't surprise us. Many developers use C as a portable, structured high-level programming language to write applications such as word processors, databases, and graphics.
Chapter 2 Functions
A source file is a translation unit. As mentioned above, the # include command only inserts the file content into the # include command. For example, such code can also be: # include "mydoc.txt" or # include "mycsource. C "but the code written in this way is a little weird, so here we compile the source file (. c file), # include the header file (. h file ). Specifically, a translation unit is a source file and Its include header file. A translation unit is compiled into a target file, and multiple translation units are connected to generate a complete executable program.
1. Inline Function
Unlike other functions, as long as a translation unit uses an inline function, the inline function must be defined repeatedly. the compiler must prepare this function to insert inline program code. Therefore, inline function definitions are often written into header files.
If all declarations of a function in a translation unit have an inline modifier without an extern modifier, this function is inline. The Inline definition is especially for translation units. It does not constitute an external definition, so other translation units can include the external definition of this function. If an external definition is attached to an inline definition, the compiler can select which definition to use.
If you use the storage class modifier extern to declare a function that is defined as inline, the definition of this function will be external (external ).
However, calling a function from another translation unit will not be compiled into inline. The inline function is actually a general function, but it is called differently in the machine code. Like a common function, the inline function has its own address. If the inline function uses macros, expand macros here. However, in inline functions that are not declared as static, you should not define modifiable objects in the form of static lifecycles.
2. Optional Independent Variables
This is the C language support for functions with variable parameters.
To use these variable parameters, you must use an object of the va_list type, which contains these parameters. This type is defined in stdarg. h.
You can use four Macros in stdarg. h to process this pointer.
Void va_start (va_list argptr, lasparam)
Type va_arg (va_list argptr, type)
Void va_end (va_list argptr)
Void va_copy (va_list DEST, va_list SRC)
Chapter 1 Statement
1. External links
An identifier with an external link indicates that the entire program contains the same functions or objects. The compiler will hand over this identifier to the connector (linker), which is resolved by the connector (RESOLVE) and linked to the same identifier in other translation units and the link library.
When declaring functions and object identifiers, if you use the extern storage type modifier, it has an external link. The only exception is: if the identifier has been declared as an internal link, make a second declaration within the scope of the first declaration, and cannot program the external link of this identifier.
Chapter 4 dynamic memory management
Implementation and Application of Binary Search Tree
Chapter 2 Input and Output
1. c common standard input/output functions
There are many Input and Output Functions in C language. The standard I/O functions include the following common functions:
(1) format input and output
Scanf, fscanf, sscanf
Printf, fprintf, sprintf
These are simple and often used to format input and output.
(2) Character Input and Output
Int GETC (File * FP), int fgetc (File * FP)
Read a character from a file. The returned value is the read character. If an error occurs, the returned value is EOF.
The above two functions have the same effect, but GETC is a macro, and fgetc is a function. Programmers often use this macro because it is faster than calling a function.
Int putc (int c, file * FP), int fputc (int c, file * FP)
Similar to the above two functions
(3) It is also a character input and output.
Int getchar (void), int putchar (int c)
These two are also macro implementations, mainly reading or outputting characters from standard input and output. Equivalent to GETC (stdin) and putc (C, stdout)
(4)String Input and Output
Char * gets (char * BUF), char * fgets (char * Buf, int N, file * FP)
Fgets is suitable for reading strings instead of gets, because gets cannot limit the number of characters to be read.
Fgets reads a maximum of N-1 characters from the stream, and adds an empty character to the end of the string. If you encounter a newline character or end of a file before reading the maximum number of characters, only the characters currently read will be placed in the buffer. If the line break '\ n' is unique ', this character will also be placed in the buffer.
Int puts (const char * s), int fputs (const char * s, file * FP)
(5) input and output of binary files
Size_t fread (void * buffer, size_t size, size_t N, file * FP ),
Size_t fwrite (const void * buffer, size_t size, size_t N, file * FP)
Chapter 2 preprocessing
1. Use Macros in macros
After the independent variable replacement and the # And # operations are executed, the pre-processor checks the substitution text in the result and expands the macro. However, null cannot be recursively expanded. If the Preprocessor encounters the name of "a macro" in the replacement text of "a macro, or if the name of "a macro" is embedded in "a macro", the name of "a macro" cannot be expanded.
Chapter 2 function Introduction
1. File Access Functions