【发布时间】:2015-06-25 08:33:55
【问题描述】:
我正在尝试计算下面给出的程序的执行时间,但它给了我一些错误
#include<stdio.h>
#include<time.h>
int main()
{
clock_t start, end;
start = clock();
int a[5] ={1,2,3,4,51};
int b[5] = {2,3,4,5,6};
int c[5] = {3,4,5,6,7};
for (int i =0;i<5;i++)
{
if(a[i]== NULL )
printf("%d element null::",a[i]);
else
printf("no null values in first array\n");
if(b[i]== NULL )
printf("%d element null::",b[i]);
else
printf("no null values in second array\n");
if(c[i]== NULL )
printf("%d element null::",c[i]);
else
printf("no null values in third array\n");
}
end = clock();
printf("Start time: %i, End time: %i \n" start, end);
return 0;
}
以下是错误和警告..
[eshwar@localhost ~]$ gcc -std=c99 ab.c
ab.c: In function ‘main’:
ab.c:18:9: warning: comparison between pointer and integer [enabled by default]
if(a[i]== NULL )
^
ab.c:24:16: warning: comparison between pointer and integer [enabled by default]
if(b[i]== NULL )
^
ab.c:30:16: warning: comparison between pointer and integer [enabled by default]
if(c[i]== NULL )
^
ab.c:39:44: error: expected ‘)’ before ‘start’
printf("Start time: %i, End time: %i \n" start, end);
为什么会给出这个警告..因为我认为我们可以像这样初始化数组??
【问题讨论】:
-
printf("Start time: %i, End time: %i \n" start, end);应该是printf("Start time: %i, End time: %i \n", start, end); -
两者有什么区别??两者看起来一样
-
逗号在
start之前,在格式字符串之后。 -
ints不能是NULL。你想在那里做什么? -
是的。与
NULL的比较没有任何意义。