Difference between int main() and void main() | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Difference between int main() and void main()

16th Sep 2020, 5:48 PM
diya
7 Answers
+ 4
The void main() indicates that the main() function will not return any value. But ,the int main() indicates that the main() can return integer type data. As void means nothing or null
16th Sep 2020, 5:52 PM
KRITI
KRITI - avatar
+ 4
int main() -->returns an Integer value. void main()--->returns nothing.. int and void are datatypes that defines the function.
16th Sep 2020, 5:53 PM
Alphin K Sajan
Alphin K Sajan - avatar
+ 2
The main() function is like other functions. It also takes arguments, and returns some value. One point we have to keep in mind that the program starts executing from this main() function. So the operating system calls this function. When some value is returned from main(), it is returned to operating system. The void main() indicates that the main() function will not return any value, but the int main() indicates that the main() can return integer type data. When our program is simple, and it is not going to terminate before reaching the last line of the code, or the code is error free, then we can use the void main(). But if we want to terminate the program using exit() method, then we have to return some integer values (zero or non-zero). In that situation, the void main() will not work. So it is good practice to use int main() over the void main()
16th Sep 2020, 6:05 PM
A S Raghuvanshi
A S Raghuvanshi - avatar
0
What's the meaning of return in a function
16th Sep 2020, 6:09 PM
Usman Abdul Matin
Usman Abdul Matin - avatar
0
A word before 'main()' function represents the return type. If it is 'void' that's means the function doesn't return anything. And if it int, that's mean the function will be return an integer.
17th Sep 2020, 11:59 AM
Rupali Haldiya
Rupali Haldiya - avatar
0
void main() without any output but int main() send output with return(<int value>); to where call the app for example console.
17th Sep 2020, 10:25 PM
Hamed Movaghari
Hamed Movaghari - avatar