C difftime()

The difftime() function returns the difference, in seconds, between time1 and time2 that is, time2 - time1.

difftime() Syntax

Following is the syntax of the difftime() function :

double difftime(time_t time2, time_t time1);

difftime() Example

Following program times the number of seconds that it takes for the empty for loop to go from 0 to 5,000,000 :

void main()
	time_t start, end;
	volatile long unsigned t;
	start = time(NULL);
	for(t=0; t<5000000; t++) ;
	end = time(NULL) ;
	printf("Loop used %f seconds.\n", difftime(end, start));

C Online Test

« Previous Function Next Function »

Like/Share Us on Facebook 😋