为什么 char* t 不指向 ctime_r 之前定义的 NULL?

Why is char* t not point to NULL defined before ctime_r?

在我使用ctime_r之前,我通过mistake.I定义了char* t而不是char* buf[32]认为char* t指向NULL,并且会有一个使用 ctime_r 后出错,例如 stycpy(t,"hello");。但我惊讶地发现 char* t 没有像 usual.Why?

那样指向 NULL

I thought char* t is point to NULL,

不,那不是真的。初始化没有通用的规则,它取决于对象的存储时间。

在您的情况下,该变量很可能是局部范围变量并且具有自动存储持续时间,因此,除非明确初始化,否则初始内容是不确定的。

引用 C11,第 6.7.9/P10 章

If an object that has automatic storage duration is not initialized explicitly, its value is indeterminate