用途 - 不可更改內容
ex.
const int x = 50;
++x; <--- error
x=3; <--- error
const char* a = "abcd";
*a=1; <--- error
a++; <--- acceptable
char* const b = "abcd";
*b = 'e'; <--- acceptable
b++; <--- error
const char* const c = "abcd";
*c = 'e'; <--- error
c++; <--- error
以下為 2-D pointer
char* d[] = {"abcd", "1234"};
const char** e = d;
**e = 'w'; <--- error
*e = "xxx"; <--- acceptable
++e; <--- acceptable
char* d[] = {"abcd", "1234"};
char* const * e = d;
**e = 'w'; <--- acceptable
*e = "xxx"; <--- error
++e; <--- acceptable
char* d[] = {"abcd", "1234"};
char** const e = d;
**e = 'w'; <--- acceptable
*e = "xxx"; <--- acceptable
++e; <--- error
char* d[] = {"abcd", "1234"};
const char* const * const e = d;
**e = 'w'; <--- error
*e = "xxx"; <--- error
++e; <--- error
本文轉載自微風論壇 : http://bbs.wefong.com/viewthread.php?tid=2238225&extra=page%3D1
作者 : cflee3000
留言列表