diffrence between void and int | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

diffrence between void and int

what is diffrence between void main and int main

14th Aug 2016, 5:25 PM
Garvit Joshi
Garvit Joshi - avatar
3 Answers
+ 2
The return type is used to tell the computer how the program ended, so the return 0 which sits at the end is only ever invoked if the program gets to the end without breaking. If something else is returned it will be told otherwise. Void on the other hand doesn't allow for returned values.
14th Aug 2016, 5:39 PM
Ahkrin
+ 1
srry i am new .... plz explain in detail
14th Aug 2016, 6:58 PM
Garvit Joshi
Garvit Joshi - avatar
+ 1
Fair enough. I'd advise reading about functions so you know was a return type is. Long story short you can tell the program to start a function, it will do some things, and if it has a return type (so int, bool, float, etc. NOT void) it will bring a value back after finishing the function. If it is void, it will just do things in the function and return nothing, no return. main itself is a function, the beginning of the program. While you're learning the bare bone basics you're fine to use void main and cut out the return 0; on the last line.
14th Aug 2016, 8:32 PM
Ahkrin