i have always read to prefer int main instead void as it returns value but what is difference between
this
insertCode:void main() { }; //and this int main() { return 0 }
as output is blank for both
where that 0 go?
i have always read to prefer int main instead void as it returns value but what is difference between
this
insertCode:void main() { }; //and this int main() { return 0 }
as output is blank for both
where that 0 go?
The difference is that the C++ standard requires main to be defined to return an int.what is difference between this
The return value, zero in this case, is returned to the operating system. The return value can be used by other processes to indicate success or failure of your program.where that 0 go?
Jim
tHAnx but can you also tell why preference given to int over void? why success or failure matters to OS if it is running? I am an beginner in C++, so confused
There IS no preference. The standard says main shall return int. Period.
The return value is a way of signalling to other programs a status code indicating the status of the operation your program performed. The OS itself may also try to check the error code to see if there was an error to try to enhance the user experience. The return value is just a service to give the OS an insight into your program. Consider for example a library which starts a program to check out books. The return value of your program may indicate if the checkout was a success or not (and why not).
The returned value is an exit status. How it's used depends on the operating system:
Exit status - Wikipedia, the free encyclopedia
tHnks, i have understood