9.5 — Pass by lvalue reference – Learn C++

PHOTO EMBED

Wed Mar 16 2022 19:41:52 GMT+0000 (Coordinated Universal Time)

Saved by @pham24n #c++

#include <iostream>
#include <string>

void printValue(std::string& y) // type changed to std::string&
{
    std::cout << y << '\n';
} // y is destroyed here

int main()
{
    std::string x { "Hello, world!" };

    printValue(x); // x is now passed by reference into reference parameter y (inexpensive)

    return 0;
}
content_copyCOPY

https://www.learncpp.com/cpp-tutorial/pass-by-lvalue-reference/