0
Question about function return command!
Hi maybe this question is stupid from me but it confuses me, when we declare a function if there is no value to return we type void! I understand that but if we want some value to return do we always write return this and that value. Since I canât save my codes for some reason Iâll give an example here: int timesThree(int x){ return x*3 } int main{ cout timesThree(6) <<endl; cout timesThree(4) <<endl; cout timesThree(10) <<endl; return 0; } Here I wrote just an example I already know what the output is going to be but my question is every time we want some value other than void should we always write return?
2 Answers
+ 2
Yeah you should write always when you want some particular value from the function.
Consider your case here you need the Variable thrice value without using the return. The thrice value of variable doesn't come to main().
So If you want some value from a function type the "return" statement.
Hope it helped you
+ 1
Exactly the answer I was looking for thanks a lot Aadhish đ