What does return -1 do in a function called in main?

What does return -1 inside of a function that is in main?
Is there a difference between returning different numbers, i.e: "return -1", "return 7", "return 2"... ?


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22


int myFunction()
{
//Start of code
//CODE
//End of code


return -1;
}


int main()
{
myFunction();

return 0;


}
Last edited on
Edit: Oops. Ignore me. I misread the question as "what's the meaning of returning -1 from main".
Last edited on
You are not using the return value of myFunction, so no, it does not matter in your case.

To actually get the return value, you'd have to assign it to a variable
1
2
int a = myFunction();
std::cout << a << std::endl;

or call it directly
std::cout << myFunction() << std::endl;

When returning a value from main (0 in your case), the return value can be used by external programs for scripts or other tools (for example, %errorlevel% in Windows), but the value returned from main doesn't affect the logic of the program itself.
Last edited on
Topic archived. No new replies allowed.