Thursday, July 9, 2009

C++ Help!!!?

under the main function, at the end we have to return value. what is the difference between returning 0 and 1? are there any other possible values to return?

C++ Help!!!?
Any value can be returned, just as with any other C++ function. In fact, the main can be thought of as a function called by a command line interpreter.





By convention, programs return 0 for success and a positive non-zero value for failure. By using different values, error conditions can be handled differently by the command line interpreter.
Reply:depends on what the value stands for. Universally 1 is on and 0 is off. So whatever needs to switch on should have a 1.
Reply:You are probably using a "void main ()" or an "int main ()" at this point to do all your operations under. Returning a "0" or any value at the end of a main tells the computer that it's done running that function. (Main is sort of considered a function). When creating functions (if you have gotten to them yet), you can make calculations or modifications to a variable and return their new value to the main using the return statement. You will also learn how to use the %26amp; in functions to automatically return certain values. But the answer to your question is you can return anything, because the main generally doesn't return values, it decides what to do with values to send them from function to function.





Edit : The difference is nothing if it's a main function.
Reply:If it's a void function, you don't need to return anything.


No comments:

Post a Comment