有没有办法将 2 个变量放在一个变量中?(有点难解释)

Alp*_*nex 3 c++ variables

例如:

int hello1;
int hello2;
int hello3;

for(int i = 1; i <= 3; i++)
{
    helloi = 99;
}
Run Code Online (Sandbox Code Playgroud)

我怎么能做类似这样的事情,但它实际上可以工作......另外,如果我在这里含糊不清,很抱歉。

Ken*_*nde 8

你要找的是一个数组:

int hello[3];

for (int i = 0; i < 3; ++i)
{
    hello[i] = 99;
}
Run Code Online (Sandbox Code Playgroud)

请注意,数组使用从零开始的索引,因此索引从 0 到 2 而不是从 1 到 3。