C语言编程声明数组的问题

WritethreefunctionsinCorC++:onethatdeclaresanintegerarrayof1,000itemsstatically,oneth... Write three functions in C or C++: one that declares an integer array of 1,000 items statically, one that declares the same large array on the stack (via a function call), and one that create the same large array from the dynamic memory. Call each of the subprograms 500,000 times and output the time required by each to finish all 500,000 calls.
静态声明一个大小为1000的整型数组
在栈上通过函数调用声明一个大小为1000的整型数组
动态内存声明一个大小为1000的整型数组
调用每个子程序500000次
输出调用500000次所需要的时间
求高手帮忙啊,,,谢谢啦~最好是C语言,不会C++
写三个函数
展开
 我来答
zhiyyao
2014-02-03 · TA获得超过1909个赞
知道小有建树答主
回答量:645
采纳率:57%
帮助的人:384万
展开全部
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main()
{
void StaticArray();
void array();
void DynamicArray();
int i = 500000;
clock_t start, finish;
double duration;
printf ("完成 %ld 次函数调用所需要的时间是: ", i) ;
start = clock();
while (i--)
{
StaticArray();
array();
DynamicArray();
}
finish = clock();
duration = (double)(finish - start) / CLOCKS_PER_SEC;
printf ("%f 秒\n", duration);
return 0;
}

void StaticArray()
{
static int a[1000];//静态整型数组
}

void array()
{
int a[1000];//在栈上声明数组
}

void DynamicArray()
{
int *p = (int *) malloc (1000 * sizeof(int));//动态声明数组
}
更多追问追答
追问
太谢谢了,我这有点晚了,明天运行一下,研究研究,好几年前学的c,都忘了,,,,有不会的地方再问你啊:)
追答
好的,欢迎追问
匿名用户
2014-02-04
展开全部
楼主不给上面的兄弟多加点分都说不过去啊。楼上兄弟给力啊!
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式