Home > Back-end >  The main function of the problem
The main function of the problem

Time:03-19

Ask you, the main function must be placed in a fixed position, or can be placed in any position?
If can be placed in any position, can you attach a few picture, thank you very much!

CodePudding user response:

What you said the location of the mean? Relative to what place? Will not be a file which ok

CodePudding user response:

C language rules, in a C program, the main () function location (),
A. Must be after the library function of the system call
B. Must be in the beginning of the program
C. Must be at the end of the program
D. Can be in any position
Answer: D
[resolution] every C program one and only one main function (main), and the program must begin from main () function to perform, and the main () function can be placed anywhere in the program,

CodePudding user response:

The main function can be placed in any position, but need to follow the principle of first sound next to use when calling function,

CodePudding user response:

This is derived from a perspective problem,
Because the main function in a sense it represents the program itself, so it is in reasonable idea the main body, center, doesn't matter, it is the origin,

's other functions, is actually the prototype to consider, the formal definition and other function calls successively,
It was to lazy to consider this question, that advocating to write all of the main function of the prototype and concentrated in the header file,

CodePudding user response:

The main () on the bottom, best
If a source file, a custom function declarations must be in the main front, () function defined in the source file is put casually
If there is a header file, think how to can be in the source file

CodePudding user response:

The main () function can be placed anywhere in the program, but if there is function in main () must be declared before main () function
  • Related