Introduction to C
C language structure is extremely compact, C language is a modular programming language, the entire program can be divided into several relatively independent function modules, mutual calls between modules and data transfer is very convenient
C language is very powerful in its expressive ability. The C language takes into account the features of high-level languages and assembly language, as well as direct access to hardware functions like assembly language, and the advantages of high-level languages that are easy for users to remember, easy to read and write.
C language Portability is very good, C language does not rely on the hardware input and output statements, input and output functions are through the call library functions to achieve, so in a computer platform developed by the program does not need to modify or only need to make simple changes can be ported to another computer platform
C language has preprocessing function, so C language can use macro instructions to improve the readability and portability of the program
C's Development process
C is a compiled language, the so-called compiled language refers to the program before it runs, need to go through the compilation and linking process:
1) Edit source file (get source file)
2) Compile the source file (get the target file)
3) link target file and library file (get executable file)
4) Run the program (get running results)
Understanding of the definition of variables
For example: int i;
The process of defining a variable is actually a process of requesting a memory unit that conforms to the data type of the variable, so it can be assumed that the substance of the variable is the format of a cell in memory, and that the reference to that format is equivalent to the read operation of the corresponding memory unit
Character arrays and strings
The array used to hold the character data is called a character array. Each array element of a character array holds one character. As one of the types of arrays, the definition, initialization, and ease of use of character arrays are the same as for general arrays
strings are treated as character arrays in the C language (others such as Java have a single string type)
It is important to note that the end of the string in the C language implies an ' n+1 ' character, so that a string of length n occupies a byte in memory
Pretreatment
Preprocessing is an important function of the C language, which is done by the preprocessing program. When a source file is compiled, the system is automatically tuned to the handler to process the preprocessing portion of the file before it is compiled into the source file. The preprocessing features provided in the C language include macro definitions , file inclusions , and conditional compilation .
The efficient use of preprocessing when designing and writing the source program can improve the portability of the project ...
Macro definition
In a C language source program, an identifier is used to represent a string, called a macro. Before the program compiles, the preprocessor replaces the identifiers in the source program with strings, a process known as macro expansion
1) macro definitions without parameters , such as
#define Macro Name string # define PI 3.1415926....//You can use this macro c=2*pi*r;
2) macro definition with parameters
#define Macro name (formal parameter) string # define MAX (A, B) (a>b)? a:b
Note the macro definition with the parameter, the macro name and (formal parameter) there is no space between, otherwise it will be expanded with an error, if there is a space, will be called when Max (A, B) is replaced (A, b) (a>b)? A:b (A, b), so it is not exactly what I expected.
The process of calling a macro is actually just a substitution of a symbol (before compilation), and the function is completely different
file contains
The file contains the contents of the specified file inserted into the current file. The use of file inclusion, can reduce the repetitive work of the program designer, improve the development efficiency of the program
1) #include < file name >
In the system set directory to find, generally through the environment variable to set, generally in this form contains the system's header file
2) #include "file name"
In the current path to find, if not found to go to the system specified directory to find, generally in this form contains user-defined header files
Conditional compilation
The introduction of conditional compilation in C language is mainly to control different pieces of code in different situations to compile, so that the code for different situations can be written in the same program file, so as to facilitate the maintenance and migration of programs. At the same time, using conditional compilation can make the target program smaller and run faster
1) #if, #else, #elif, #endif命令
#if constant Expression code snippet 1#else code snippet 2#endif
If the value of a constant expression is true (not 0), compile Code Snippet 1, or compile Code snippet 2
2) #ifdef, #else, #ifndef, #endif命令
#ifdef Macro name code snippet 1#else code snippet 2#endif
If the macro name is already defined earlier, compile Code Snippet 1, or compile Code snippet 2
Linux C Programming Learning 1---C language Foundation (Introduction, preprocessing ...) )