Will parameters not stored in the variable be copied at run time?

I have the following code:

#include <iostream>
#include <string>

using namespace std;

void foo(string input){
    //perform operations...
}

int main(){
    string x, y;
    cin >> x;
    cin >> y;
    foo(x + y);
    return 0;
}

Will foo parameters be copied at runtime? In other words, x and y will be concatenated, then copied, and then transferred to foo? or will they be concatenated and transferred to foo without being copied to go to foo?

Is there any way to check this? I'm not sure what to look for, so links are welcome if a similar question already exists.

+4
source share
2 answers

will x and y be concatenated, then copied, and then passed to foo? or will they be concatenated and transferred to foo without being copied?

. . , .

?

. , - .

+2

-, , ( , ?).

, , foo. ( ), , . .

+1

Source: https://habr.com/ru/post/1606479/


All Articles