是什么char * const的,并为const char *之间的区别? [英] What is the difference between char * const and const char *?

查看:135
本文介绍了是什么char * const的,并为const char *之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么区别:

  char * const的

 为const char *


解决方案

不同的是,为const char * 是一个指向一个为const char ,而 char * const的是一个常量指针字符

被指向的第一,值不能被改变,但指针即可。第二,该值被指向可以改变但指针不能(类似于参考)。

有也是

 为const char * const的

这是一个常量指针,以一个恒定的字符(所以没有什么办法可以改变)。

请注意:

以下两种形式是等价的:

 为const char *

 字符常量*

这种情况的确切原因在C ++标准中描述的,但要注意,避免混淆是非常重要的。我知道有几家编码标准是preFER:

 字符常量

 为const char

(带或不带指针),使常量的位置元素是一样的指针常量

What's the difference between:

char * const 

and

const char *

解决方案

The difference is that const char * is a pointer to a const char, while char * const is a constant pointer to a char.

The first, the value being pointed to can't be changed but the pointer can be. The second, the value being pointed at can change but the pointer can't (similar to a reference).

There is also a

const char * const

which is a constant pointer to a constant char (so nothing about it can be changed).

Note:

The following two forms are equivalent:

const char *

and

char const *

The exact reason for this is described in the C++ standard, but it's important to note and avoid the confusion. I know several coding standards that prefer:

char const

over

const char

(with or without pointer) so that the placement of the const element is the same as with a pointer const.

这篇关于是什么char * const的,并为const char *之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆