What is time(NULL) in C?

后端 未结 8 1056
别跟我提以往
别跟我提以往 2020-12-07 19:12

I learning about some basic C functions and have encountered time(NULL) in some manuals.

What exactly does this mean?

相关标签:
8条回答
  • 2020-12-07 19:46
    int main (void)
    {   
        //print time in seconds from 1 Jan 1970 using c   
        float n = time(NULL);   
        printf("%.2f\n" , n);      
    }      
    

    this prints 1481986944.00 (at this moment).

    0 讨论(0)
  • 2020-12-07 19:56

    You can pass in a pointer to a time_t object that time will fill up with the current time (and the return value is the same one that you pointed to). If you pass in NULL, it just ignores it and merely returns a new time_t object that represents the current time.

    Nb:time(&timer); is equivalent to timer = time(NULL);

    0 讨论(0)
提交回复
热议问题