Re 浅谈C和C++中的const关键字

This article contains many errors, I just list them simply.

BTW About const concept in C/C++, I have 2 articles.

Can’t understand. This idea is so strange.
If possible, you should use const as possible. It is a good contract.

const int n; 这种声明方式是错误的
This definition method is wrong. (should NOT declaration!)
extern char* const p; // this is declaration, p as extern variable

I never heard the concept “指针常量”, it should be “the pointer points to constant” 指针指向常量!!

const int a=3; int *pa=&a; *pa=4; printf(“%d\n”,*pa); printf(“%d\n”,a);

!!!! WTF !!
C++ has a keyword const_cast !!

Try following code:
const int a=3;
int *pa= const_cast < int * > (&a); *pa=4;

Will print out “4 4” as result.

《Re 浅谈C和C++中的const关键字》上有4条评论

    1. Indeed, if we use “fixed” to replace “constant” will be better.

      You could see my whole blog, I have explained the topic very well too!

  1. 指针常量是有的

    int * const a = &b;

Noname 发表评论 取消回复