I just stumbled over the following line of code
cout << &"Blahh" << endl;
The compiler doesn’t give an error and on the console the address is displayed. It works all correctly without any problem. If I replace “Blahh” with an int, so
cout << &10 << endl;
the code won’t compile. For short: a string literal works but an integer literal not.
What is the reason why cout << &"Blahh" << endl; works and cout << &10 << endl; not?
Because
"Blahh"has an address in memory (it’s an l-value).10doesn’t (it’s an r-value).http://en.wikipedia.org/wiki/Value_%28computer_science%29