+ 2

What is the purpose of returning in a function?

I don't understand. There are example programs that return 0 or nothing, is that necessary? I am asking because the program still seems to work fine, even if I remove that line.

8th Sep 2018, 9:26 AM
Aysha Ferdaushi Islam
Aysha Ferdaushi Islam - avatar
3 Respostas
+ 4
return 0 in main signifies that the program executed correctly. in modern compilers, it can be omitted
8th Sep 2018, 9:59 AM
hinanawi
hinanawi - avatar
+ 1
If the function declaration returns a type other than "void", the "return" statement is mandatory. The compiler will warn you if you omitted this or can return automatically the initial value of the corresponding data type (only for implicit data types like int, float, string, etc.).
8th Sep 2018, 9:30 PM
Vasile Eftodii
Vasile Eftodii - avatar
0
firstly you need to know that there are two types of functions impure and pure.pure has datatype as return type and impure has void has return type and in last line of pure you need to return a value with a datatype similar to as you have declared in function header.
9th Sep 2018, 6:35 AM
Vivek Mishra
Vivek Mishra - avatar