由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - a simple C++ question
相关主题
数组指针的问题请问const myClass &src 和myClass const &src有什么区别?
const char *p, is it ok to change p[1] ?问一道brainbench上的问题
最新某公司onsite面试题 (转载)谁给解释一下这个c question
c++ 弱问题:static const char* const 这两个const 分别是什么意思?问一个 char * 和 char [] 的问题
[c++] reference 真得不能bound to a second object 么?const reference in copy constructor
C++ Q05: pointer to constant variableint F::*x = &F::x是什么意思?
why int** cannot convert to const int** ?a question about const reference
A question about c++ pointer请教一个const pointer的问题
相关话题的讨论汇总
话题: const话题: char话题: pointer话题: object话题: constant
进入Programming版参与讨论
1 (共1页)
s****y
发帖数: 4
1
actually three:
1. what's the difference of
const char* p
char const *p
char* const p
what i understood is---first is a pointer to constant object;
second and third are same , a constant pointer to an object
am i right?
2. is this true:
const char* p = const char *p
3. why const char* can be both a character and a string declaration
t*****l
发帖数: 121
2

first and second are the same, pointer to constant object
yes
how?

【在 s****y 的大作中提到】
: actually three:
: 1. what's the difference of
: const char* p
: char const *p
: char* const p
: what i understood is---first is a pointer to constant object;
: second and third are same , a constant pointer to an object
: am i right?
: 2. is this true:
: const char* p = const char *p

z**i
发帖数: 394
3
A small piece of code to verify your guess. :)
/*
By ZuZi Sun Nov 4 19:16:45 CST 2007
* const int* p: a int* pointer pointing to a const object
* int* const p: a char* pointer who is a const type itself
* int const *p: same with const char* p
*/
#include
using namespace std;
int main()
{
int a = 1;
int b = 10;
// an int* ponter pointing to a const int
const int* p2const = &a;
//(*p2const)++; //error: increment of read-only location
p

【在 s****y 的大作中提到】
: actually three:
: 1. what's the difference of
: const char* p
: char const *p
: char* const p
: what i understood is---first is a pointer to constant object;
: second and third are same , a constant pointer to an object
: am i right?
: 2. is this true:
: const char* p = const char *p

s****y
发帖数: 4
4
thanks for the answers, to summarize,
const char *p = const char* p = char const *p = char const* p
a pointer to constant object
char* const p
a constant pointer to an object
is this right?

【在 z**i 的大作中提到】
: A small piece of code to verify your guess. :)
: /*
: By ZuZi Sun Nov 4 19:16:45 CST 2007
: * const int* p: a int* pointer pointing to a const object
: * int* const p: a char* pointer who is a const type itself
: * int const *p: same with const char* p
: */
: #include
: using namespace std;
: int main()

r*******y
发帖数: 290
5
right
parse at the asterisk

【在 s****y 的大作中提到】
: thanks for the answers, to summarize,
: const char *p = const char* p = char const *p = char const* p
: a pointer to constant object
: char* const p
: a constant pointer to an object
: is this right?

c********x
发帖数: 84
6
Key word Const control the attribute of the variable of its right
hand side, keep this in mind, it can't fool you.
1 (共1页)
进入Programming版参与讨论
相关主题
请教一个const pointer的问题[c++] reference 真得不能bound to a second object 么?
问题C++ Q05: pointer to constant variable
C++ Function Pointer Array 的问题why int** cannot convert to const int** ?
为啥允许这样的const设计A question about c++ pointer
数组指针的问题请问const myClass &src 和myClass const &src有什么区别?
const char *p, is it ok to change p[1] ?问一道brainbench上的问题
最新某公司onsite面试题 (转载)谁给解释一下这个c question
c++ 弱问题:static const char* const 这两个const 分别是什么意思?问一个 char * 和 char [] 的问题
相关话题的讨论汇总
话题: const话题: char话题: pointer话题: object话题: constant