gpt4 book ai didi

c++ - 在 C++ 中定义变量

转载 作者:太空狗 更新时间:2023-10-29 19:39:45 25 4
gpt4 key购买 nike

我总是对“定义变量”这个概念感到困惑。定义是什么意思?

例如:

void main {
map<int,int> *infoMap;

if() {
//some check here,if it passes this check, then new infoMap
}

infoMap = new infoMap;

}

也是一样

map<int,int> *infoMap;

map<int,int> *infoMap = new inforMap;

定义一个变量?

最佳答案

最上面的是声明,或者如果您愿意,可以是定义。这里,编译器为变量分配空间。

最下面的是一个作业。在这里,编译器填充它在定义时分配的空间。如果您想将变量的值更改为其他值,您可以进行多个赋值。

关于c++ - 在 C++ 中定义变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7740925/

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