Clock Function

  • It is used for getting the no. of clock ticks that have elapsed since the program started execution .
  • It returns value -1 if the time is not available .
  • One should divide the time by CLOCKS_PER_SECOND to get the time in seconds .


  • Syntax:

       
    Declaration :
    clock_t clock(void);
    Calling :
    clock(); OR clock()/CLOCKS_PER_SECOND;

    Example:

    
      #include <time.h>
    
      #include <stdio.h>
    
    
    
      int main()
    
      {
    
       
    
        printf("Elapsed time: %u secs.\n", clock()/CLOCKS_PER_SEC);
    
       
    
      return 0;
    
      }
    
         
    Back