0

What is the use of “void main()”?

Whenever I compile using “void main” as my entry point the output always error. Why like that? Should I use int main?

23rd Sep 2018, 3:48 PM
Carly
Carly - avatar
5 Answers
0
provide your code
23rd Sep 2018, 3:53 PM
Faisal Rahman
Faisal Rahman - avatar
0
#include <stdio.h> void main() { int x = 5; if (true); printf(“hello”); }
23rd Sep 2018, 4:12 PM
Carly
Carly - avatar
0
you’re right. I try it many times but the output errors. So I try int main and it run.
24th Sep 2018, 2:23 AM
Carly
Carly - avatar
0
main() is a function called by OS, and it should return an int to tell status. return 0; // successful if returned something else then OS will know something went wrong with the code. return - 1, 1, 2, - 2 //:-( I know this that void main() doesnt return anything, so doesnt mean anything for OS, maybe compiler adds it. I only remember void main () in text book codes to save 1 line from return statement.
26th Sep 2018, 4:30 PM
Morpheus
Morpheus - avatar