Retuen Statement values

1. Is it always necessary for a return value of main() to be an integer.
2. What happens if the return value of main() is not integer.
3. When a return value other than 0 is returned - does it always indicate that an error has occurred ?
4. If the answer to '3' is yes then what steps does the OS take ?

1. Is it always necessary for a return value of main() to be an integer.

In C, the compiler may allow main() to return a void, but its behaviour is undefined and therefore its highly not recommended. As a reference, the C++ standard explicitly prohibits returning void, and some compilers would ignore your void and convert it to an int returning zero.

2. What happens if the return value of main() is not integer.

Well, if its a void, the consequences of such a program are technically unpredictable, but it is likely it would just return 0. If its a char or any other kind of non-int, assuming the compiler will even allow this, the compiler would probably attempt to cast it into an int, but this all entirely dependant on the compiler. All this speculation is avoided by using the standard int.

3. When a return value other than 0 is returned - does it always indicate that an error has occurred ?
4. If the answer to '3' is yes then what steps does the OS take ?

The meaning of the return value always depends on the context of the call. For instance, if you make a program to run from a batch script, you might want its return integer be a part of a switch of some kind with all non-zero actions that do different things to the script.

Normally, the Operating system will treat zero as good and non-zero as bad, but honestly it doesn't usually care what it returns, unless the process that requested the program to run actually needs to know that information.

I beleive you do something like this in windows XP. (Since I am logged into Ubuntu right now I cant test this).. Right after you execute the command in a batch program, the ERRORLEVEL environment variable should be assigned the last returned code, so doing this should show you that return code.

When a return value other than 0 is returned - does it always indicate that an error has occurred ?
When program terminates with 0, this means program has been ended correctly as per complier.
else if it ends up with non-zero or value 1 then it means that there is code still awaiting for execution or abnormal termination may occured (like exit() function in c).

It may be due to thread at the run-time that requires 1/0, im not sure about them.
But 0 means everything is cool as per complier else 1 or non-zero means abnormal termination of program or run-time issues affecting programs.

Hi. so this is actually a continuation from another question of mine[Here](https://www.daniweb.com/programming/software-development/threads/506795/dynamically-add-values-into-datagridview-cell-from-listbox-vb2010) but i was advised to start a new thread as the original question …

I have a 2d matrix with dimension (3, n) called A, I want to calculate the normalization and cross product of two arrays (b,z) (see the code please) for each column (for the first column, then the second one and so on).
the function that I created to find the ...

Write a C program that should create a 10 element array of random integers (0 to 9). The program should total all of the numbers in the odd positions of the array and compare them with the total of the numbers in the even positions of the array and indicate ...