gpt4 book ai didi

c++ - 常量 int = int 常量?

转载 作者:IT老高 更新时间:2023-10-28 13:23:27 27 4
gpt4 key购买 nike

例如是

int const x = 3;

有效代码?

如果是的话,意思是一样的

const int x = 3;

?

最佳答案

它们都是有效的代码并且它们都是等价的。对于指针类型,尽管它们都是有效代码但不等价。

声明 2 个常量:

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

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

const int *p = &someInt;

声明一个不能被改变为指向别的东西的指针:

int * const p = &someInt;

关于c++ - 常量 int = int 常量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3247285/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com