const int = int const? [英] const int = int const?

查看:139
本文介绍了const int = int const?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,是

int const x = 3;

有效的代码?

它的含义与

const int x = 3;

推荐答案

它们都是有效的代码,它们都是等效的。对于指针类型,虽然它们都是有效的代码,但不是等价的。

They are both valid code and they are both equivalent. For a pointer type though they are both valid code but not equivalent.

声明两个常量的int:

Declares 2 ints which are constant:

int const x1 = 3;
const int x2 = 3;

声明一个指针,其数据不能通过指针改变:

Declares a pointer whose data cannot be changed through the pointer:

const int *p = &someInt;

声明不能更改为指向其他对象的指针:

Declares a pointer who cannot be changed to point to something else:

int * const p = &someInt;

这篇关于const int = int const?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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