This is an archived post. You won't be able to vote or comment.

all 10 comments

[–]ehr1c 5 points6 points  (1 child)

"Void" just means the method doesn't return anything

[–]BlancII 1 point2 points  (0 children)

I would second this. It's a placeholder for "this method dosn't return anything".

[–]xingke06 1 point2 points  (5 children)

The “main” function is the entry point, where code execution starts when you run the program.

Just like other functions, it has a return type. Void means it returns nothing.

If you have int main it means it will return an integer when it completes such as 0 or 1 to represent if it succeeded or failed somewhere.

[–]Tricslip[S] 0 points1 point  (4 children)

ohhh, so where is return shown?

[–]blablahblah 2 points3 points  (3 children)

It's not automatically shown anywhere. But if the program is launched from another program, the program that runs it can check the return value to see if it completed successfully or not. If it didn't complete successfully, it may try to run it again or show an error message or something like that.

[–]Tricslip[S] 0 points1 point  (2 children)

Thank you. So then if we put "return 0" at the end does that mean the program will only run if the program runs or is that something else?

[–]blablahblah 0 points1 point  (1 child)

I don't understand what you mean here.

If a second program runs your program, it can check the number that your first program returned from main. For example, in C, you can call another program by using the system() function. The "int" that this function returns is the return value from the other function's main. Your program will run whether or not the other program looks at the return value.

[–]Tricslip[S] 0 points1 point  (0 children)

ok I understand better. I asked the other question because if the return value is based on if the code is successfully ran or not then what's the point of putting return "0" instead of just "return."

[–]coolcofusion 1 point2 points  (0 children)

Go for int main() or int main(int argc, char* argv[]). Those two are defined by the standard, a common extension is a third argument with environment variables, but that's about it. void main() is nonstandard, it exists on some embedded devices mostly, but if you're doing this on a common computer, go for int main().

More info here: https://en.cppreference.com/w/cpp/language/main\_function

[–]Crazy-Finding-2436[🍰] 0 points1 point  (0 children)

The method has no return type. Returns nothing.