Hi,
your function contains code that you need often (if don't want to copy paste it each time, it's convenient to put it into a function)
... like the math functions ... 'tangens' f. ex.
You program now calls a function, but the returned value will be stored in previously allocated memory by your application
1 2 3 4 5 6 7 8
|
double a = 0;
...
...
a = tan(x);
| |
However, by "knowing" the return type, the compiler can check, wether there is enough memory, and if the return value will be interpreted in the right ( say "intended" ) way.
1 2 3 4 5 6 7 8
|
int a = 0;
...
...
a = tan(x);
| |
would result in a warning, because the return-value will be read as an "int", which is not what "tan" would usually return.
It might as well give erros, if return - types are complicated and can not be recasted so easily, as is the case with structs and so on.
However, thats the reason, why return types are nessecary, as far as I know.
Void as return type just means : "the function doesn't return anything".
Greets,
fluppe