0

Can we use void main () .... instead of int main ().

if we cannot use please tell the reason

30th Jul 2017, 6:39 AM
DEEPENDU PANDIT
DEEPENDU PANDIT - avatar
3 Réponses
+ 2
It depends on the compiler. But the standard for main is to return an integer, so that is what you should do. The reason is that when the compiler makes the exit call, it needs to pass in an integer as a parameter, which is typically the value of what you return in main. If you use void main, the compiler will usually either give you an error or make it so the compiled code returns and exits with 0 anyways
30th Jul 2017, 6:47 AM
aklex
aklex - avatar
+ 9
As of the latest standard, main() must return int to signal the OS regarding exit status.
30th Jul 2017, 7:24 AM
Hatsy Rei
Hatsy Rei - avatar
+ 2
Another advantage to using int instead of void is that you can end the program early with the return statement.
30th Jul 2017, 7:25 AM
Keto Z
Keto Z - avatar