Bruce Eckel's Thinking in C++, 2nd Ed | Contents | Prev | Next |
//: C08:Safecons.cpp // Using const for safety #include <iostream> using namespace std; const int i = 100; // Typical constant const int j = i + 10; // Value from const expr long address = (long)&j; // Forces storage char buf[j + 10]; // Still a const expression int main() { cout << "type a character & CR:"; const char c = cin.get(); // Can't change const char c2 = c + 'a'; cout << c2; // ... } ///:~
//: C08:Constag.cpp {O} // Constants and aggregates const int i[] = { 1, 2, 3, 4 }; //! float f[i[3]]; // Illegal struct S { int i, j; }; const S s[] = { { 1, 2 }, { 3, 4 } }; //! double d[s[1].j]; // Illegal ///:~
const bufsize = 100; char buf[bufsize];