C language int main ()void main and int void declare variables

hello I am Disheng, the following is the author's own opinion, if there is any mistake, please be sure to point it out, thank you♪(・ω・)ノ

Let’s first talk about int main(), void main(), and void main(void).

I didn’t know why before. I searched on the Internet, good guys, if I didn’t understand int main(), I just got involved. void main() void main(void) 

In fact, it is not that messy, the main function uses int main() and return 0; at the end of the final function body; then, the question is, why do you need to add return 0;? Why can't it be return 1;? emm.....int main() means that this is a standard return value function. As for why its return value is 0, let me listen to bb (/dog head).

Int main() is actually a function, int main(void) is not a problem. In fact, there is a program (we don’t know) before int main() to call our main function. At this time, return0 also has It makes sense. This 0 is returned to the place where main is called, that is, that small piece of code, that small piece of code to check the return value, and report to our operating system, so that it is meaningful to some people, you can use some methods Let’s check whether the last returned value of our program is 0 (traditionally, it depends on whether this is 0). If it is 0, what to do. It also shows that our program shows that there is nothing wrong with it.

Then say the void int of the custom function

For example, we define a function named cheer

Void cheer (int i) and void cheer (void) to declare a function means that the defined function is not allowed to have a return value. In this case, what we want is the "side effect" of this function.

Note: When the function we define does not need to pass in parameters, use void cheer(void). There must be nothing in the brackets (). Nothing does not mean that the function has no parameters, but that the function has uncertain parameters ( Passing in parameters at this time is prone to errors), so when we make it clear that the function does not use parameters, we add void in the parentheses, and when we use parameters, we add formal parameters to standardize it~~

As for custom int cheer (int a, double b), this means that the custom cheer function is a parameter with a return value.

 

 

Guess you like

Origin blog.csdn.net/qq_51182221/article/details/114952618