两者速度一样,都是0.0000sec
赋值为0,建议使用int c[100]={0};,不用写头文件<string.h>,而且写代码速度更快,只需要一行
赋值为-1,只能使用memset(c, 0, sizeof(int)*100);
#include<stdio.h>
#include<time.h>
int main(){
// 利用初始={0}赋值为0
clock_t start,end;
start = clock();
int a[99999]={0};
int b[99999]={0};
int c[99999]={0};
int d[99999]={0};
int e[99999]={0};
end = clock();
printf("time=%f\n",(double)((end-start)/CLK_TCK));
}
#include<stdio.h>
#include<time.h>
#include<string.h>
int main(){
//用初始memset赋值为0
clock_t start,end;
start = clock();
int a[99999];memset(a, 0, sizeof(int)*99999);
int b[99999];memset(b, 0, sizeof(int)*99999);
int c[99999];memset(c, 0, sizeof(int)*99999);
int d[99999];memset(d, 0, sizeof(int)*99999);
int e[99999];memset(e, 0, sizeof(int)*99999);
end = clock();
printf("time=%f\n",(double)((end-start)/CLK_TCK));
}