通过方法分配变量、返回变量或指向变量时,哪个更快?
案例一:
函数声明
void foo(int* number)
{
*number = 5;
}
用法
int main()
{
int number;
function(&number);
cout << "Number: " << number;
}
案例2:
函数声明
int foo()
{
int number = 5;
return number;
}
用法
int main()
{
int number;
number = function();
cout << "Number: " << number;
}
PS: In case 2, I created a variable and returned it instantly. I know this doesn't make sense, but this is the closest example I can find for the situation I'm dealing with, since I'm initializing an actual object, which requires creating the object first, editing it, then returning it