in this few lines i told the program to compute 5+1+2=? a being 5 b being 2, then i told it to use a, add one to it, then subtract the result of that to variable b. then i told it to display the result in a simple text line.

so, after a bit, i got onto strings and stuff, and this is an example of string that i typed up

'This line corresponds to the beginning of the definition of the main function. The main function is the point by where all C++ programs start their execution, independently of its location within the source code. It does not matter whether there are other functions with other names defined before or after it - the instructions contained within this function's definition will always be the first ones to be executed in any C++ program. For that same reason, it is essential that all C++ programs have a main function.'

Edit: Yeah, all apps require a main method to run, that's a common convention. I don't think there's anything about them having to return anything, though. I can't think of an obvious reason main() would need to return anything, anyway. As it is, if you declare a method to return an integer [int main()] and it always returns zero, it doesn't need to return anything. void main() means it doesn't return anything, so no return statement is needed. But whatever, it's still best to follow the tutorial.

For what it's worth, all of my Java programs begin with a " public static void main() "

No, the "}" at the end terminates it. the 'return' line means that the function will return whatever is after it, in this case a zero. Usually you'd see some variable being manipulated and returned. Say in your program up there, you could do this:

No, the "}" at the end terminates it. the 'return' line means that the function will return whatever is after it, in this case a zero. Usually you'd see some variable being manipulated and returned.

The "return some_int_value" called from 'main' doesn't directly terminate the process (nor the closing parenthesis of the 'main' function), but returns execution to the CRT code (added by the linker) which called the 'main' function at the beginning, after initializing all the internal C/C++ runtime stuff.

of the program, which is passed by CRT to either 'ExitProcess' WinAPI function in Windows, '_exit' kernel call in Linux/Unix, '0x4C' function of '0x21' interrupt in DOS, or other system function that terminates the process. The status code can be then used by calling program or script (batch) to decide what to do next (for example if the called program was non-interactive). Returning 0 usually means that the program finished its execution without errors (where errors are not unhandled exceptions, but program's internal errors, for example like "no argument passed", "file not found", etc).

At least Windows, DOS, and Unix/Linux use integer exit status codes, and the same such argument for program termination functions, so that's why the 'main' is of int type.

I guess some clarifications are needed. First, while 'void main()' may be acceped by some compilers, it's explicitly forbidden by the C standard. Plus, besides the fact that main() may be declared with zero or two arguments (or even more, depending on the platform), it is otherwise like any other function.

Conceptually, the main function is called by the OS when the program is started, thus returning from it is the same as exiting the program (the same as calling exit()). The closing bracked ('}') is simply a token marking the end of the function definition in the source code, and is not the same as returning from it. This may be a bit confusing, since, if the code compiles, the compiler must add a 'return 0' at the end of the function. *

The value returned from the main function is actually used and does have a meaning in some contexts. A 0 means that everything went well, and any other value implies that something went wrong. In some cases, the value is used to tell exactly what made the program fail. xargs, for example, is a command-line utility used in Unix-like systems which returns different values depending on the specific error.

This value is not actually used by the user (unless you're in the command-line or using a debugger), but mostly by other programs or scripts. For example, a script may use it to decide if a command needs to be retried, or even if it can be retried.

In Java, the main function does not return anything since the program implicitly returns 0 when all threads die. This means a Java app automatically quits when main() ends and you did not meddled with multithreading. However, System.exit() may be called directly if you actually need to return an exit code.