gpt4 book ai didi

c - c中可变数组的内存分配

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

变量数组的内存是在运行时还是编译时分配的?

int n; 
printf("Enter size of the array: ");
scanf("%d",&n);

int a[n];
for(int i=0; i<n; i++)
{
a[i] = 0;
}
}

最佳答案

由于数组的大小 n 是在运行时定义的,因此分配也在运行时发生。

内存是从栈上分配的,比从堆上分配要快。但是你可以保留多少内存要低得多。

关于c - c中可变数组的内存分配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28589274/

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