[Solved] What does mean this return


You got 3 ways to write a function which are effectively doing the same thing. They are all assigning _p with the value of p if the value of p is not negative.

  1. (void) in your function says that it is not going to return anything.
    Therefore the return; is not doing anything but exiting from the function.

  2. & 3. For a function with return type void, you don’t need an explicit return statement at the end of the function body.

ie.

-(void)setSomething:(int)p{
  <code>
  return;
}

and

-(void)setSomething:(int)p{
  <code>
}

are effectively same.

There are no other lines which will get executed after the return statement in else case of 2. Even if you have the else block or not, the program will exit from the function there.

solved What does mean this return