In other words, there is a pen question that is said to be a monthly salary of 2 W:
# Include "stdio. H"
Void print ()
{
*
}
Void main ()
{
}
It must be written in part *.CodeMake the entireProgramAfter running the command, output "Hello world". Some people say that this is not simple, so they wrote the code like this:
View Source
Print? 01.
# Include "stdio. H"
02.
Void
Print ()
03.
{
04.
Printf
(
"Hello World"
);
05.
}
06.
Void
Main ()
07.
{
08.
Print ();
09.
}
This is indeed okay, But it violates the requirements of the question, because the question cannot be modified to the main function, it seems that we have no choice, when we learned the C/C ++ language, we clearly stated that the main function is the main function of the program and the entry function of the program. However, the main function is empty now, how can we execute subfunctions?
In fact, this pen test is not about our understanding of the basic knowledge, but about our ability to discover and solve problems. Sometimes, when a road fails, we have to change the road, by searching for information, we found that C ++ can actually modify the entry function.
Here we need a c ++ precompiled identifier # pragma comment () to help us solve this problem. The usage type is Pragma comment (comment-type, ["commentstring"]).
Comment-type is a predefined identifier that specifies the annotation type. It should be one of compiler, exestr, Lib, and linker.
Commentstring is a string that provides additional information for comment-type.
Here we need to use linker to modify link settings:
# Pragma comment (linker, "/entry: Print ")
Have you seen it? Use the/entry parameter to set the main function to print when the program is linked. In this way, the print function is the main function of the entire program. Instead, it replaces the main function, the main function is a subfunction.
Complete code and running results:
As for # pragma comment (Lib, "msvcrt. lib"), it is because the puts function is used. If printf is used, do not use this sentence.