`const`的特殊用法

时间:2017-11-28 13:26:43

标签: c const

关于关键字const,我已经学会了(纠正我,如果我错了),并且我了解到如果你从右到左阅读它是非常容易的:

int a = 0;                 // `a` is an integer. Its value is initialized with zero
const int b = 0;           // `b` is an integer which is constant. Its value is set to zero
int * c = &a;              // `c` is a pointer to an int. `c` is pointing to `a`.
int * const d= &a;         // `d` is a constant pointer to an int. It is pointing to `a`.
const int * e = &a;        // `e` is a pointer to an int which is constant. It is pointing to `a`.
int * const f = &a;        // `f` is a constant pointer to an int. It is pointing to `a`.
const int * const g = &b;  // `g` is a constant pointer to a constant integer. It is pointing to `b`.

但是这是怎么回事:

int const * h;

h是指向常量int的指针吗?如果是,与e有什么不同?

这是关于什么的:

int const i;

i这个类型与b相同吗?

0 个答案:

没有答案