You might have noticed by now that some of the functions we are using, like the math functions, yield results. Other functions, like newLine, perform an action but donβt return a value. That raises some questions:
What happens if you call a function and you donβt do anything with the result (i.e. you donβt assign it to a variable or use it as part of a larger expression)?
The answer to the third question is βyes, you can write functions that return values,β and weβll do it in a couple of chapters. I will leave it up to you to answer the other two questions by trying them out.
Any time you have a question about what is legal or illegal in C++, a good way to find out is to ask the compiler. It will let you answer your question by throwing an error⦠or not!
#include <iostream>
using namespace std;
void multiply(int x, int y) {
cout << x * y << endl;
}
int main() {
int x = 2;
int y = 4;
cout << multiply(x,y);
}