clock function(Processor Clock) in C Language – example and detail

In the C Programming Language, the clock function returns the elapsed processor time (as measured in clock ticks) due to the fact the commencing of the program execution.

Syntax

The syntax for the clock characteristic in the C Language is:

clock_t clock(void);

Returns

The clock feature returns the elapsed processor time (as measured in clock ticks) considering the starting of the application execution.

If you want to decide the elapsed time in seconds, take the result of the clock function and divide by way of CLOCKS_PER_SEC.

If there is an error (ie: the time is unavailable or can not be represented), the clock function will return -1.

Required Header

In the C Language, the required header for the clock characteristic is:

#include <time.h>

Applies To

In the C Language, the clock characteristic can be used in the following versions:

ANSI/ISO 9899-1990

Similar Functions

Other C features that are similar to the clock function:

time function <time.h>

See Also

Other C functions that are noteworthy when dealing with the clock function:

difftime function <time.h>