+ 4

Diffrence between main( ) and void main(void)

Please explain briefly 😅

3rd Feb 2022, 6:22 PM
SIMRAN
SIMRAN - avatar
6 ответов
+ 4
Both are not prefered in modern compilers these days.. both gives warnings of same type. therefore no difference Use : int main(){ // } Above both are, in C/C++, you get warnings, may it produce error in c++, depends on compiler implementation. return type not int. https://www.sololearn.com/Discuss/1511677/?ref=app https://www.sololearn.com/Discuss/2395549/?ref=app https://www.sololearn.com/discuss/268996/?ref=app https://www.sololearn.com/discuss/81360/?ref=app https://www.sololearn.com/discuss/583759/?ref=app
3rd Feb 2022, 6:30 PM
Jayakrishna 🇮🇳
+ 3
Jayakrishna🇮🇳 Yaa I know, but it's my assignment question 😅 So please give proper answer !
4th Feb 2022, 2:51 AM
SIMRAN
SIMRAN - avatar
+ 2
The standard is for C int main(void) if you are not using arguments per standard 5.1.2.2.1 Program startup or int main(int argc, char *argv[]) if you are requesting or expecting arguments in the command line. void main is an error because the returned int is the signal to main if the program completed successful or with error. Now with the current standard return 0; is not required in main but still good practice. https://open-std.org/jtc1/sc22/WG14/www/docs/n1256.pdf PDF Page 24
3rd Feb 2022, 9:24 PM
William Owens
William Owens - avatar
+ 1
SIMRAN I don't understand "what is mean by proper answer!!! "? still for you. I guessed the links answers you more.. main() { } No return type is set but compiler give warning but assigns befault return type, so basically it returns int type. and return 0; added at end. void main() { } return type is void, so it returns nothing. But if compiler implementation expects a return type then it gives you warning as " return type is void, not int ". void main(void) { } Means return type void and it accepts no arguments... Hope it helps...
4th Feb 2022, 10:38 AM
Jayakrishna 🇮🇳
0
Int main() show that our main function will return values and we do soo by the use of return 0; at the end.
5th Feb 2022, 12:02 PM
Lilart
Lilart - avatar
0
John, well written. I would contest that return 0 is still returned however not needed to be written in code with current standard.
5th Feb 2022, 11:23 PM
William Owens
William Owens - avatar