Difference between different types of return

0

What is the difference of adding a return -1 and a return 1 to any function of type int? Reading the code of a program that circulated in a forum, in some functions it used return -1 and in others it used return 1.

    
asked by Jogofus 07.06.2017 в 01:41
source

1 answer

1

Short answer: It depends on you.

Long answer:

It depends on you, it can be a lot of difference. the return of a function is a message that is sent from the function called to the function that invoke it and not only exist the values -1 0 and 1 when you speak of an int function, keep in mind that the values of int are from -2,147,483,648 to 2,147,483,647. so why limit yourself to -1 to 0 and to 1. Well, in part because they are simple numbers but in the programming you are the programmer and you have the power .

>

Then for example you can do a function suma;

suma = funcion_suma(5, 2);
.
. 
.
int funcion_suma(int x, int y){
    return x + y;
}

and there you see how important the return is ...

Or you can manage your own secret code

//si retorna 0 es porque el usuario quiere papas fritas 
//si retorna 1 quiere papas mas refresco
// si retorna 2 quiere helado de vainilla
// si retorna 52 quiere la cajita feliz
// si retorna -2 es porque no se decide
// si retorna -2000 se gano el premio

However, if you do not care at all, if you do not capture that value and start asking yourself those kinds of questions, I recommend you do the void function and you will not have those existential dilemmas p>     

answered by 07.06.2017 / 03:50
source