+ 26
When to use 'void main ()' and when to use 'int main ()' in C language ? Will anyone help me by posting examples, please.
I have seen that somewhere 'void main ()' is used and somewhere 'int main ()' with 'return 0'. In some compilers I also have found that after using 'int main ()' and then not using 'return 0' gives the correct output. Why ?
10 Respuestas
+ 8
@Martin
Thanks Martin for helping me in such an awesome way. Happy friendship day Martin.
+ 5
Always use int main().
void main() is just acceptable on some compilers.
+ 5
Nice quote:
"
void main() is useful mainly as an indication that you're using a textbook written by someone who doesn't know the C language very well.
"
Source:
https://stackoverflow.com/questions/18928279/how-does-int-main-and-void-main-work
+ 3
@Martin - only int main() is standard C (and it has been like that from ANSI C89).
void main() was kept around only for backwards compatibility, but you should avoid using it.
+ 2
void main is for Turbo C++, and it's better not to use it.
+ 1
"void main ()" is also used with the Arduino IDE rather than "int main ()".
0
void main is used when you want that your function should not return any value. However, if you want the function to return an int value, we use int main