![]() |
VOOZH | about |
C
According to coding standards, a good return program must exit the main function with 0. Although we are usingvoid main() in C, In which we have not suppose to write any kind of return statement but that doesn't mean that C code doesn't require 0 as exit code. Let's see one example to clear our thinking about need of return 0 statement in our code.
Example #1 :
It works fineRuntime Error:
NZEC
This is correct output
It works fineRuntime Error:
NZEC
GeeksforGeeks
C++
In case of C++, We are not able to use void keyword with ourmain() function according to coding namespace standards that's why we only intend to use int keyword only with main function in C++. Let's see some examples to justify these statements.
Example #3 :
prog.cpp:4:11: error: '::main' must return 'int' void main() ^
GeeksforGeeks
prog.cpp:4:11: error: '::main' must return 'int' char main() ^ prog.cpp: In function 'int main()': prog.cpp:7:9: error: invalid conversion from 'const char*' to 'int' [-fpermissive] return "gfg"; ^
GeeksforGeeks