0

I am posting a program that I came across. Can anyone explain me

  1. What "0x7FFFFFFF" means?
  2. How does ctime() function work?

#include<stdio.h>
#include <time.h> 

int main()
{ 
     time_t Variable = 0x7FFFFFFF; 
     printf("Variable value is = %s \n", ctime(&Variable) ); 
     return 0; 
} 
kotAPI
  • 387
  • 1
  • 7
  • 20

3 Answers3

0

ctime converts time_t value to string. From Wiki

time_t as an arithmetic type, but does not specify any particular type

0x7FFFFFFF is 2147483647 in decimal equal to 2^31 − 1. Max Value that can be represented in a 32-bit signed integer.

Sadique
  • 22,572
  • 7
  • 65
  • 91
0

0x7FFFFFFF is the maximum value that can be represented in a 32-bit signed integer. If time_t is a signed integer type then ctime(&Variable) represents the end of the world on a 32-bit system. We'll go into the undefined world from there. ;-)

However, the end has been postponed by the use of 64-bit types for time_t.

P.P
  • 117,907
  • 20
  • 175
  • 238
0

usually ctime used in following way

/* ctime example */
#include <stdio.h>      /* printf */
#include <time.h>       /* time_t, time, ctime */

int main ()
{
  time_t rawtime;

  time (&rawtime);
  printf ("The current local time is: %s", ctime (&rawtime));

  return 0;
}

We first save current time in rawtime variable using time() and then display it in human readable string by using ctime()

Jeegar Patel
  • 26,264
  • 51
  • 149
  • 222