一些很无聊的问题,关于const的位置。

1、const int a和int const a什么区别?

答:没区别,这个我是知道的。

2、const int*a和int const* a什么区别?

答:还是没区别,即*修饰离变量a最近,都是表示指针是常量,且所指向的对象也是常量?

3、const int* a和int* const a什么区别?

答:完全不同,前者见2,后者是a是常量不能改指向,但指向的对象可以更改的。

类似的把指针换成&引用,同理。

Leave a Reply

Your email address will not be published. Required fields are marked *