0
about function
why if we change the int ( which is showed in parenthesis) to void for below code then output shows compilation error ?? #include <iostream> using namespace std; (int) timesTwo(int x) { return x*2; } int main() { cout << timesTwo(8) << endl; cout <<timesTwo(5) << endl; cout <<timesTwo(42) << endl; }
2 Answers
+ 7
void can't return any value, it just performs some tasks for the caller function. If you want to make it void, then print the result within it.
void timesTwo(int x) {
cout << x*2 << endl;
}
You can see this post if you are confused about when we need to return any value ^_^
https://www.sololearn.com/Discuss/342545/?ref=app
+ 1
Thank you so much