0

Can i use void main instead of int main???

in our school we are taught to use void main can anyone explain me the difference???

29th Oct 2016, 4:08 AM
M Zeya
M Zeya - avatar
4 Respostas
0
Void means something line "no return value", while int has to return integer. It is always bad to use void main(), because only some compilers support it, so it's possible you will get an error just because you use void main(). When you use int main(), it needs to return a value (return 0 means "program executed successfuly"). In some compilers return 0 is not necessarry, because they will add it to the end if you didn't do that. So always use 'int main()' with 'return 0' statement in the end (in case your teacher allows you to do that :D)
29th Oct 2016, 6:00 AM
Daniel Oravec
Daniel Oravec - avatar
0
yes u r right but int main didn't allow us to freeze the screen it is possible only with void main.isnt it?
29th Oct 2016, 6:08 AM
M Zeya
M Zeya - avatar
0
It should be possible also with int. Try to use cin.get(), or if you use windows, use system("pause") (but your code will only work for windows).
29th Oct 2016, 6:34 AM
Daniel Oravec
Daniel Oravec - avatar
0
yes I use win10 os
29th Oct 2016, 6:37 AM
M Zeya
M Zeya - avatar