c++

i understand that when you return a value,its goes to the OS buh i dnt understand what does OS do with these returned values??? cn sum1 plz help me wid tat?
The return value of the program can be used by other programs and also scripts to figure out if everything went fine or if there was an error.

On Windows run in the Command Prompt:
echo %errorlevel%

On Linux run in the Shell:
echo $?
does tis means that os checks the return values? if 0 thn program works fine , otherwise error?(in c++)
closed account (S6k9GNh0)
OS doesn't check the return value.
thats wat m nt understanding....why does returnd values r sent 2 OS in d first place? wat does operating system do?
anyways..thnxx guys 4 replyin...
Maybe if you used proper grammar we could understand you more...
Anyways the operating system can check if the program passed or failed as catfish mentioned.
Forget the OS. It is usually programs, scripts, or you, who run programs. All these preferably want to know what did happen. The return value can be tested, and based on it choose the next thing to do.

foo && bar && gaz

A simple one-liner on suitable shell. It will execute program "foo". If that ends with "success", then the "bar" will run. If still successful, the "gaz" will run last. If either of the first returns a non-success, the rest are not run.

If you know the error codes returned by a program, you can (with if-else) do different things depending on why the program did quit.

A batch execution system can keep statistics on "jobs" and point out if the jobs fail. Nobody wants to give CPU-hours from multi-million clusters to computing jobs that do not succeed.


Have you ever compiled a C++ program? Did you use an IDE? Compilation invokes preprocessor, compiler, and linker. All must succeed. The IDE has to know the outcome so that it can show you something. Return values are really useful.
Last edited on
Topic archived. No new replies allowed.