睡前无聊看了下APUE的习题,测试下const pointer,详细信息看注释
#include
int main()
{
int a = 3;
const int * b = &a;
// *b++; compile access, run like *(b++)
// (*b)++ compile error , *b can not edit
printf("%d\n", a);
int c = 3;
// int const * d = &c; compile access, 'int const' like 'const int'
int * const d = &c;
//*d++; // compile error, d can't change
printf("%d\n", c);
int e[2] = {3, 4};
const int * f = e;
// f[0]++; error, *f can not change
// f[1]++; error, *(f + 4u) can not change
return 0;
}