2011年(100)
分类: C/C++
2011-04-22 10:04:01
char *p = "Hello" // non-const pointer, non-const data const char *p = "Hello"; // non-const pointer, const data char * const p = "Hello"; // const pointer non-const data const char * const p = "Hello"; // const pointer, const data |
const char* p; char const* p; |
char* const p; |
p = "foo"; // Does not compile *p = 'f'; // Compiles! |
const char* const p; char const* const p; |
p = "foo"; *p = 'f'; |
const char** p; char const** p; |
p = ptr-to-ptr-to-char; // Compiles *p = ptr-to-char; // Compiles **p = 'f'; // Does not compile |
char* const* p; |
p = ptr-to-constptr-to-char; // Compiles *p = ptr-to-char; // Does not compile *p = constptr-to-char; // Does not compile **p = 'f'; // Compiles |
char** const p; |
p = ptr-to-ptr-to-char; // Does not compile p = constptr-to-ptr-to-char; // Does not compile *p = ptr-to-char; // Compiles **p = 'f'; // Compiles |
const char* const* p; |
const char** const p; |
const char* const* const p; |