gpt4 book ai didi

c++ - 与动态内存分配 C++ 混淆

转载 作者:太空宇宙 更新时间:2023-11-04 12:30:05 25 4
gpt4 key购买 nike

<分区>

我对动态内存分配有点困惑,我希望有人能帮我解决这个问题。

假设我们有一个程序:

int length = 0;

cout << "Enter the size of the array" << endl;
cin >> length;
cin.ignore();

int numbers[length];

Wouldn't this still be dynamic memory allocation since the array size is being defined at runtime after the user enters in the specified length?

与使用:

int numQuestions = 0;

cout << "How many questions would you like to add?" << endl;
cin >> numQuestions;
cin.ignore();

Question *newQuestions = new Question[numQuestions];

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