C++ Primer 读书笔记2(三)

2015-01-26 23:13:02 · 作者: · 浏览: 12
n in memory).

Lvalues and rvalues also differ when usedwith decltype. When we apply decltype to an expression (other than a variable),the result is a reference type if the expression yields an lvalue. As anexample, assume p is an int*. Because dereference yields an lvalue,decltype(*p) is int&. On the other hand, because the address-of operatoryields an rvalue, decltype(&p) is int**, that is, a pointer to a pointer totype int.&Pg121

12 Moreover,except for the obscure case where -m overflows, (-m)/n and m/(-n) are alwaysequal to -(m/n).
13
//  note s as a reference to const; the elements aren't copied and can't be changed 
for (const auto &s : text) { // for each element in text
cout << s;        // print the current element
// blank lines and those that end with a period get a newline
    if (s.empty() || s[s.size() - 1] == '.')
        cout << endl;
    else
        cout << " ";  // otherwise just separate with a space
}
14

// the behavior of the following loop is undefined! 
while (beg != s.end() && !isspace(*beg))
*beg = toupper(*beg++);   // error: this assignment is undefined