+ 1
When we use void ,and when we use return in function in c ++
please help me
2 Answers
+ 6
You use void when your functions doesnt return anything. Aka your functions does not give out any value back to your system.
For example, if your functions just does writing stuff on the console, then you do not need to return a value, hence you use void.
You use return if you want the function to give the system a value.
For example, if you want the function to add 2 values and give back the value, that is where you use return.(And int as the return-type)
+ 3
when our function does not need to return a value we use void.
for example we can write a function to send data to a server and of course the function does not send anything in response.