[Solved] What main(++i) will return in C


First of all, the declaration of main() is supposed to be int main(int argc, char **argv). You cannot modify that. Even if your code compiles, the system will call main() the way it is supposed to be called, with the first parameter being the number of parameters of your program (1 if no parameter is given). There is no guarantee it will always be 1. If you run your program with additional parameters, this number will increase.

Second, your printf() is attempting to print the return value of main(++i), howover, your main() simply don’t return anything at all. You have to give your function a return value if you expect to see any coherence here.

And finally, you are not supposed to call your own program’s entrypoint, much less play with recursion with it. Create a separate function for this stuff.

7

solved What main(++i) will return in C