+ 1

When it's better to use void?

I'm having difficulty understanding when to apply void as a function header. And "use void when you don't want anything returned" really does not help me understand.

22nd May 2017, 9:47 AM
Tayeba Monsur
Tayeba Monsur - avatar
2 Respostas
+ 8
void x (int a) { cout <<a; //prints in function. Return type not required } int x (int a) { return a; //returns value to main for use }
22nd May 2017, 10:01 AM
Pixie
Pixie - avatar
+ 2
You usually call a function somewhere, so if you for example just call it so it does something internally then you use void, but if you want to use the result of what the function did, you don't use void, but some other return type
22nd May 2017, 1:16 PM
‎ɐısıօլɐ
‎ɐısıօլɐ - avatar