Demonstrate pointer usage

Source: Internet
Author: User

 /* <Br/> the following example demonstrates that the pointer corresponds to the address. When the address content is changed, the pointer content also changes <br/> */<br/> # include <winsock2.h> <br/> # include <stdio. h> <br/> # include <stdio. h> <br/> # include <sys/timeb. h> <br/> # include <time. h> </P> <p> int evutil_gettimeofday (struct timeval * TV, struct timezone * tz) <br/>{< br/> struct _ timeb TB; </P> <p> If (TV = NULL) <br/> return-1; </P> <p> _ ftime (& TB ); <br/> TV-> TV _sec = (long) TB. time; <br/> TV-> TV _usec = (INT) TB. millitm) * 1000; <br/> return 0; <br/>}</P> <p> # define evutil_timeradd (TVP, UVP, vvp) /<br/> do {/<br/> (vvp)-> TV _sec = (TVP)-> TV _sec + (UVP)-> TV _sec; /<br/> (vvp)-> TV _usec = (TVP)-> TV _usec + (UVP)-> TV _usec;/<br/> If (vvp) -> TV _usec> = 1000000) {/<br/> (vvp)-> TV _sec ++;/<br/> (vvp)-> TV _usec-= 1000000; /<br/>}/ <br/>} while (0) <br/> # defineevutil_timersub (TVP, UVP, vvp) /<br/> do {/<br/> (vvp)-> TV _sec = (TVP)-> TV _sec-(UVP)-> TV _sec; /<br/> (vvp)-> TV _usec = (TVP)-> TV _usec-(UVP)-> TV _usec;/<br/> If (vvp) -> TV _usec <0) {/<br/> (vvp)-> TV _sec --;/<br/> (vvp)-> TV _usec + = 1000000; /<br/>}/ <br/>} while (0) <br/> # defineevutil_timerclear (TVP)-> TV _sec = (TVP) -> TV _usec = 0 </P> <p> int main (INT argc, char * argv []) <br/>{< br/> struct timeval TV; <br/> struct timeval * TV _p; </P> <p> evutil_gettimeofday (& TV, null); </P> <p> TV _p = & TV; </P> <p> printf ("current time is: % s/n", ctime (& TV _p-> TV _sec )); <br/> // assign the address to the pointer </P> <p> struct timeval TVM; <br/> TVM. TV _sec = 10; <br/> TVM. TV _usec = 0; <br/> // increase the TV time <br/> evutil_timeradd (& TV, & TVM, TV _p ); </P> <p> printf ("after add 10 second is: % S/R/N", ctime (& TV _p-> TV _sec )); </P> <p> return 0; <br/>}</P> <p>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.