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. |