由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - 一道c++ primer的问题
相关主题
在线等一道P家的电面coding题C语言高手帮我看看下面代码,哪里错了啊,谢了
弱问OJ的Surrounded Regions那题一个C++题
lc里面那个max points O(n3)的算法也不慢啊面试问了个“master c++”的这个问题,答不出来,直接给枪毙了 (转载)
一个关于指针的问题问一道旧题
白痴问题:TreeNode 里面有指向 parent 的指针么?C++ Q29: extern and const together
Stack的Top方法可以返回const引用么?C++ question
请教一段小程序问个c++的问题
请教一个指针的面试题搞不清C++里的constant expression
相关话题的讨论汇总
话题: const话题: int话题: ic话题: cpi话题: cpic
进入JobHunting版参与讨论
1 (共1页)
y*******i
发帖数: 100
1
(a) int i = -1;
(b) const int ic = i;
(c) const int *pic = ⁣
(d) int *const cpi = ⁣
(e) const int *const cpic = ⁣
答案说(d)不合法,其他都合法。d怎么不合法了,不是给一个const 的指针赋值了吗
g***y
发帖数: 764
2
ic is a const int
but cpi is not pointing to a const int

【在 y*******i 的大作中提到】
: (a) int i = -1;
: (b) const int ic = i;
: (c) const int *pic = ⁣
: (d) int *const cpi = ⁣
: (e) const int *const cpic = ⁣
: 答案说(d)不合法,其他都合法。d怎么不合法了,不是给一个const 的指针赋值了吗
: ?

y*******i
发帖数: 100
3
(e)怎么就合法了,e不但指针是const,还多了一个它指向的对象也要const?
j**w
发帖数: 382
4

ic is a constant. that is, the value of ic can not be changed.
(d) int * const cpi. It means, cpi is a constant, and cpi points to an int.
Since cpi is a pointer. "cpi is a constant" just means the cpi points to a "
fixed" address. Say nothing about the content of that fixed address.
If (d) is valid, we can do (*cpi)++. In this case, the value of ic is
changed. It's wrong.
For (e)
const int *const cpic. cpic is a constant, and is pointed to a const int.
Since ic is also a const int. It's good.
Just my 0.02.

【在 y*******i 的大作中提到】
: (a) int i = -1;
: (b) const int ic = i;
: (c) const int *pic = ⁣
: (d) int *const cpi = ⁣
: (e) const int *const cpic = ⁣
: 答案说(d)不合法,其他都合法。d怎么不合法了,不是给一个const 的指针赋值了吗
: ?

1 (共1页)
进入JobHunting版参与讨论
相关主题
搞不清C++里的constant expression白痴问题:TreeNode 里面有指向 parent 的指针么?
自己瞎想出来的一道题,请大家点评Stack的Top方法可以返回const引用么?
Leetcode上面的题Max Points on a Line请教一段小程序
Max Points on a Line 用c++map老是没法compile请教一个指针的面试题
在线等一道P家的电面coding题C语言高手帮我看看下面代码,哪里错了啊,谢了
弱问OJ的Surrounded Regions那题一个C++题
lc里面那个max points O(n3)的算法也不慢啊面试问了个“master c++”的这个问题,答不出来,直接给枪毙了 (转载)
一个关于指针的问题问一道旧题
相关话题的讨论汇总
话题: const话题: int话题: ic话题: cpi话题: cpic