What would be the different between void and int functions? When do i use which? Would void be used when just printing out a message or a variable value? like cout << value;
Or would it just be text?
And is int used when you actually do calculations within it?
void is used when you are not required to return anything from the function to the caller of the function.
for eg.
void no_return_fn()
{
cout<< "This function will not return anything" << endl;
return; // returns nothing or void
}
int is used when you have to return an integer value from the function to the caller of the function
for eg.
int return_sum_of_integers_fn(int a, int b)
{
cout<< "This function returns an integer" << endl;
return (a + b); // returns an integer
}
Do you want the function to return anything? If not, then it should be void. If you want it to return an int, then it should be int. If you want it to return something else, then it should have some other return type.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With