Which is better practice?

This is just a contrived example. I'm just wondering whether its better to pass a function's return value straight to another function that has a const reference parameter or create a variable beforehand.

Example this is my test function prototype
 
void testFunction(const int&);


And say otherFunction() returns an int value then which method is better?

1
 
testFunction(otherFunction());


2
1
2
int testVar = otherFunction();
testFunction(testVar);


In method 1 every time I use my parameter inside testFunction() will it call otherFunction, hence wasting memory, or will it have stored the return value of otherFunction?
In method 1 every time I use my parameter inside testFunction() will it call otherFunction

No, otherFunction() will be executed once, its return value (a nameless temporary object of type int) will be used to initialize the testFunction's parameter, and then testFunction() will begin execution.
Thanks for the help!
Topic archived. No new replies allowed.