我发布了一个我遇到的程序。任何人都可以解释我
#include<stdio.h>
#include <time.h>
int main()
{
time_t Variable = 0x7FFFFFFF;
printf("Variable value is = %s \n", ctime(&Variable) );
return 0;
}
答案 0 :(得分:0)
ctime
将time_t
值转换为字符串。来自Wiki
time_t作为算术类型,但未指定任何特定类型
0x7FFFFFFF
是2147483647
,十进制等于2 ^ 31 - 1.最大值,可以用32位有符号整数表示。
答案 1 :(得分:0)
0x7FFFFFFF
是可以用32位有符号整数表示的最大值。如果time_t
是有符号整数类型,则ctime(&Variable)
表示32位系统上的end of the world。我们将从那里进入 undefined world 。 ; - )
但是, end 通过使用time_t
的64位类型 postponed 。
答案 2 :(得分:0)
通常以下列方式使用ctime
/* 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;
}
我们首先使用time()
将当前时间保存在rawtime变量中,然后使用ctime()