Assigning/Initializing references in function args

c++

Solution

Your parameter (`x`) is created/initialized in the context of the calling function. The string literal `"hello" has static storage duration.

The standard doesn't specify the form of memory in which either of those is stored, but in a typical case, the string literal will reside in some memory that's initialized directly from data in the executable file, and `x` will be created on the stack (with the address of the literal passed to initialize it if you don't pass something else in its place).

Problem

I am from C background and trying to understand what this means: ``` void f(const string &x = "hello") { } ``` Is x set to a default value if nothing is passed in? Where does "hello" reside?

Original source