+ 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.
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
}
+ 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