演示了指针的使用

 /* 下面这个例子演示了指针是对应着地址,当改变地址的内容的时候,该指针的内容也改变 */ #include <Winsock2.h> #include <stdio.h> #include <stdio.h> #include <sys/timeb.h> #include <time.h> int evutil_gettimeofday(struct timeval *tv, struct timezone *tz) { struct _timeb tb; if(tv == NULL) return -1; _ftime(&tb); tv->tv_sec = (long) tb.time; tv->tv_usec = ((int) tb.millitm) * 1000; return 0; } #define evutil_timeradd(tvp, uvp, vvp) / do { / (vvp)->tv_sec = (tvp)->tv_sec + (uvp)->tv_sec; / (vvp)->tv_usec = (tvp)->tv_usec + (uvp)->tv_usec; / if ((vvp)->tv_usec >= 1000000) { / (vvp)->tv_sec++; / (vvp)->tv_usec -= 1000000; / } / } while (0) #define evutil_timersub(tvp, uvp, vvp) / do { / (vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec; / (vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec; / if ((vvp)->tv_usec < 0) { / (vvp)->tv_sec--; / (vvp)->tv_usec += 1000000; / } / } while (0) #define evutil_timerclear(tvp) (tvp)->tv_sec = (tvp)->tv_usec = 0 int main(int argc, char* argv[]) { struct timeval tv; struct timeval *tv_p; evutil_gettimeofday(&tv,NULL); tv_p = &tv; printf( "current time is : %s/n", ctime( &tv_p->tv_sec) ); //把地址赋给指针 struct timeval tvm; tvm.tv_sec = 10; tvm.tv_usec = 0; //增加tv的时间 evutil_timeradd(&tv,&tvm,tv_p); printf("After add 10 second is :%s/r/n",ctime( &tv_p->tv_sec)); return 0; }  

你可能感兴趣的:(演示了指针的使用)