+ 2

[DUPLICATE] What is difference between void main() and int main() in c++

differences

26th Mar 2018, 5:53 PM
Pranesh Prashar
Pranesh Prashar - avatar
9 Answers
+ 5
To add onto what they're saying, it's returning an EXIT STATUS (usually 0 for success, another number for failure) back to the program that called it, which is the Operating System in the case of the main loop. This informs the OS of the program's exit status and can allow it to properly display/handle errors.
26th Mar 2018, 6:05 PM
Fata1 Err0r
Fata1 Err0r - avatar
+ 2
Though it is standard for the main function to be int main() not void main()
26th Mar 2018, 6:02 PM
TurtleShell
TurtleShell - avatar
+ 1
One returns something (int) the other does not
26th Mar 2018, 5:58 PM
TurtleShell
TurtleShell - avatar
+ 1
int main() would have some sort of return like return 0; if it doesn’t it will add the previous line of code because it’s a special function. void main() would not have the return statement
26th Mar 2018, 6:01 PM
TurtleShell
TurtleShell - avatar
+ 1
You can use any function or class in your void main() function but you cannot use a return statement in the function like return 0; or return 500; ect
26th Mar 2018, 6:05 PM
TurtleShell
TurtleShell - avatar
+ 1
thanks brothers..thanka for help..what i jave learnt in my senior secondary class
26th Mar 2018, 6:06 PM
Pranesh Prashar
Pranesh Prashar - avatar
0
It's our pleasure, Pranesh. Best of luck to you brother!
26th Mar 2018, 6:08 PM
Fata1 Err0r
Fata1 Err0r - avatar
- 1
????
26th Mar 2018, 5:59 PM
Pranesh Prashar
Pranesh Prashar - avatar
- 1
but we we write getch() in void main function
26th Mar 2018, 6:02 PM
Pranesh Prashar
Pranesh Prashar - avatar