Why int main instead of void main?

why int main instead of void main?

Attached: help_zoom.jpg (471x449, 24K)

Because the program is supposed to return an integer value depending on the exit state (I think return 0 is finished with no errors)

I have a better question...

Why not use void main(void) and not have to return 0 at the end of your program?

So that you can exit with an error status.

But what's the point of exiting with an errorlevel if your program is known to be able to complete itself without errors? I mean if all you're doing is college-level shit programs that you know the outcome will always return errorlevel 0, why look down on using the shorthand of void main(void)?

It's not like the professors give a shit unless they're specifically teaching you about how to create programs with errorlevel feedback.

For scriptability. Almost every program that's more complex than cat will have some failure condition, and it can be very useful for a script that calls your program to be able to detect that it failed.

So why would you need scriptability in a college-level program that only your professor will see?

And why do you want to be a skiddy with C language?!

So it can simply return its exit status.
It's pretty useless in my opinion since you can already do that via exit. It should have just been 0 by default, unless you return something else explicitly via exit.

But whatever.

Thanks for answers. I guess later on it will be important to get a return value.

In college you're learning good practices for stuff you write in the real world. Of course your fizzbuzz or whatever won't be useful in any real way apart from earning a grade. But you should be learning how to write a good program.
Later when you go to write a real utility, no matter whether you write it in C, C++, Python, Rust, Node.js, etc., it may be useful to call it from a shell script or similar, in which case it's very helpful if you can tell whether execution was successful. Even if it's something interactive like an editor, it may be called to write a commit message or whatever. If it encounters an error, crashes, is killed, terminated by a HUP, etc., whatever called it should behave differently than if it completed successfully.

For piping.

>if your program is known to be able to complete itself without errors
There are no perfect programmers and no perfect programs.

Why do you bother having a shower if you're just going to get dirty again later anyway

There are also external conditions like users that fed it nonsensical arguments, files that cannot be read, kill signals arriving during execution.

This is a very good question. Showers are bloat.

>Who is Terry Davis

Because I have a gf, unlike you

The problem with int main(), tough, is that your program actually requires an integer input. Not all programs require an integer input and void main() can actually allow any type of input, though it'd still have to return an errorlevel unless you use void main(void).

So what evidence is there that void main(void) is actually bad practice?

OP have you seen real world C/C++ code?
That shit is like full of IF_NULL, IF_NON_ZERO, RETURN_SUCCESS, ERROR_OK, #ifdefs everywhere for platform specific code.
It's like putting armor on your original code. Besides doing what it has to do, it also should provide a platform for delegating errors to a level that can handle them accordingly, meaning that you don't kill your process when your file reading routine encounters an error. It should report to a greater scope code that knows whether to close the program or just just a pop-up window.

Actually, why int main(void)? The void is weird.

The void only allows for the program to not check for an errorlevel. And depending on what you're programming, that can be a good thing.

I explained why int main is void in this post:
pastebin com/LbDk56Es

int main() does in fact take an int. That will be argc, the count of command line arguments. If you don't put a variable name for it, it exists but is ignored.

int main(void) explicitly gets rid of it.

int main(int argc, char argv[][]) gives you the count of arguments in argc, and an array of strings with one argument each in argv.

Truth on Jow Forums...

You didn't get attention for that shitpost on /x/, so what makes you expect you'd get it on Jow Forums?