Word Source VC World - C language classroom
Self-archiving, also dedicated to the same Delphi programmer as me
File contains
The file contains another important feature of the C predecessor. The file contains the general form of the command line to: #include "file name" in front We have multiple times with this command contains the header file of the prominent function. For example: #include "stdio.h" #include "math.h" file contains the command to insert the specified file into the command line position replacing the command line, thereby connecting the specified file and the current source program file into one Source File. In programming, the file contains is useful. A large program can be divided into multiple modules, which are programmed separately from multiple programmers. Some common symbol constants or macro definitions can be used separately, and can be used in the beginning of other files that contain the file with the command. This way, avoiding the public quantities in each file, saving time, and reduces errors.
The following points are required to include the commands: 1. The file name containing the command can be enclosed in double quotes, or enclose the purse. For example, the following writing methods are permissible: #include "stdio.h" #include
2. An incrude command can only specify an included file, if there are multiple files to include, you need to use multiple include commands. 3. The file contains allowed nested, ie, in one included file, another file can be included.
Conditional compilation
The pretreatment program provides conditional compilation. Different program parts can be compiled by different conditions, thus producing different target code files. This is useful for programs and commissioning. There are three forms in the condition. The following introduces: 1. First form: #ifDef identifier Procedure 1 #Else block 2 #ENDIF Its function is that if the identifier has been defined by the #define command to block 1 Make compilation; otherwise the block 2 is compiled. If there is no block 2 (which is empty), the #else in this format can be written as: #ifdef identifier program #ENDIF #define num okmain () {struct stu {int num; char * name; Char sex; float score;} * ps; ps = (struct stu *) Malloc (Struct Stu); ps-> num = 102; ps-> name = "zhang ping"; ps-> sex = 'm '; ps-> score = 62.5; #ifdef numprintf ("number =% d / nscore =% f / n", ps-> num, ps-> score); # elseprintf ("Name =% s / nsex =% C / N ", PS-> Name, PS-> SEX); # Endiffree (PS); PRINTF statement. And in the first line of the program has made macro definitions for NUM, therefore responds to the first PrintF statement, the result is output, and the number and grade are output. In the first line macro definition of the program, define NUM represents the string OK, which can also be any string, no string, write as: #define NUM also has the same meaning. Only the first line of the cancel process will be compiled the second PrintF statement. The reader can trial. 2. Second form: #ifndef identifier program segment 1 #ELSE block 2 #ENDIF and the first form difference is to change "IFDEF" to "IFNDEF". Its function is to compile the block 1 if the identifier is not defined by the #define command, otherwise the block 2 is compiled. This is opposite to the first form of functionality.