Defining Function Type

Greetings Sir/Mam,

I’ve a doubt regarding defining a function type, i’ve gone through the videos related to this query several times but unfortunately i’m getting confused in deciding whether the function should return nothing (void) or a value based upon defined datatype, I know that void is used when we don’t want function to return any value, but i’m unable to decide whether my defined function should return a value or not

Can you please brief me some points about when should we use return type void or some value??

Hi Harsh
There are no such rules that in this case you should use return or in that you should use void . It all depends upon you like if i build a function of first n natural number then i might think of use return statement here and then call print for this function in main class and you might think of using void and printing side by side. Both of us are correct so it all depend upon our thinking. While a few points which you can remember are:-

***Void function calls can ONLY be used w/in stand-alone statements.

***Conversely, value-returning function calls can be used in

  1. output: e.g., cout statements
  2. assignment
  3. arguments in other function calls

I hope your doubt will be clear now if you still face any issue please let me know.