关于关键字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
相同吗?