1. The fact that a link cannot be initialized with a value instead of another variable is understandable and logical, but how is it that if you specify the link as const, then it becomes possible to initialize it with a value?
const std::string& s = "String"; 2. If you return a variable from a function, then why in the same place this variable can not be assigned a value? How does it turn out that returning a variable by reference makes it possible to assign values to the returned variables?
#include <iostream> #include <string> std::string f(std::string& s) { return s; } int main() { std::string s = "string"; f(s) = "another string"; std::cout << s << std::endl; } The top code at the place where the function is used should generally look like this, s = "another string"; , but the output "string" instead of "another string" looks strange to me. Could you clarify for me these details?