0

#include <iostream> using namespace std; int main() { cout << "Hello world!"; return 11; } is something wrong

18th May 2018, 3:08 PM
Shivam Kumar
8 Réponses
+ 2
If you look at how the main function is defined: int main() { return 0; } ^At the beginning, 'int' is the return type of the function, so it expects that you return an 'int.' I believe in the newer standards it may no longer be required, as it's implied instead, but I haven't messed with it in awhile so don't quote me on that. For the return status, 0 is intended for successful exit status. 1 (or any other number than 0) is intended for a failed exit status.
18th May 2018, 3:29 PM
Fata1 Err0r
Fata1 Err0r - avatar
+ 3
In this scenario, the main function's return statement is simply returning an exit status to your OS. It's purpose won't be noticeable to you for what you're doing here.
18th May 2018, 3:18 PM
Fata1 Err0r
Fata1 Err0r - avatar
+ 1
try it on code playground :)
18th May 2018, 3:13 PM
storm
storm - avatar
+ 1
Since the return statement is part of the main function (entry/exit point of the program), it's returning back to the OS itself (which is what called the program/main function).
18th May 2018, 4:14 PM
Fata1 Err0r
Fata1 Err0r - avatar
0
return "11" or return 0 is same ? i am getting the same output all the time
18th May 2018, 3:16 PM
Shivam Kumar
0
ohk why they had written" return 0" they could also write " return"
18th May 2018, 3:25 PM
Shivam Kumar
0
so do you mean that in this code by return is must as it takes the control out of the function
18th May 2018, 4:06 PM
Shivam Kumar