What is the meaning of return statement in Objective-C>?
For example, a simple calculator method to add numbers:
-(double) add: (double) value
{
accumulator += value;
return accumulator;
}
Does it mean that the result will be returned (or stored?) back to accumulator? What if there would be no return statement in that case?
Also, how to explain the statement “return 0;” that we write in the end of each program.
Thanks in advance.
The value given in the return statement is the value returned by the function or method. In your example, the value in
accumulatorwill be the result of calling the method-add:, like this:barwill get the value that was inaccumulator.In Unix (and remember, both MacOS X and iOS are flavors of Unix), programs return a value when they exit. The value 0 indicates normal termination; other values indicate some sort of error or abnormal termination.