[置顶] 关于这个野指针

今天有饭傻,只是先声明指针,却没为他们赋值。

#include <time.h>
#include <stdio.h>
#include <sys/time.h>
int main( void)
{

 struct tm *local;
 struct timeval tv1,tv2;

 time_t t;
 t=time(NULL);
 local=localtime(&t);
 printf("local hour is: %d \n",local->tm_hour);
 local=gmtime(&t);
 printf("utc hour is: %d \n",local->tm_hour);
 printf("time is %s \n",asctime (local));
 printf("time is %s \n",ctime(&t));
 gettimeofday(&tv1,NULL);
 printf("interval time is %ld \n",tv1.tv_sec);
 sleep(10);
 gettimeofday(&tv2,NULL);
 printf("interval time is %ld \n",tv2.tv_sec);
 return 0;
}

如果不加 #include <sys/time.h>,则会

time1.c:8:17: 错误: ‘tv1’的存储大小未知
time1.c:8:21: 错误: ‘tv2’的存储大小未知


你可能感兴趣的:(struct,null,存储)