Please, consider the following program:
#include <stdio.h>
#include <time.h>
#define N 10000
int main ()
{
time_t begin1,end1;
float diff1;
int begin2, end2, diff2;
int i;
begin1 = time (NULL);
begin2 = time (NULL);
//consuming time
for(i=0;i<N;i++){
printf("%.2f%%\n",(i/(float)N)*100);
}
end1 = time (NULL);
end2 = time (NULL);
diff1 = difftime(end1, begin1);
diff2 = end2-begin2;
printf("%f\t%d\n",diff1, diff2);
return 0;
}
We can see that the program works perfectly. It calculates the time differences in two ways. And both provide the same answer. I'm wondering why it is possible to implicit convert the result of calling time(NULL)
to an integer variable in this way.