clock function returns current time

Syntax

C clock function has the following syntax.

clock_t clock(void);

C clock function is from header file time.h.

Description

C clock function returns time or -1 if the time is not available.

To transform this value into seconds, divide it by CLOCKS_PER_SEC.

Example

C clock function gets current time.


#include <time.h>
#include <stdio.h>
//from w  ww  .j a  va  2 s .  c o m
int main(void)
{
 
  printf("Elapsed time: %u secs.\n", clock()/CLOCKS_PER_SEC);
 
}

The code above generates the following result.





















Home »
  C Language »
    Function Reference »




assert.h
ctype.h
math.h
setjmp.h
signal.h
stdio.h
stdlib.h
string.h
time.h
wctype.h