O'Reilly logo

Just Enough C/C++ Programming by Guy W. Lecky-Thompson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Code Sample 12.2: Manipulating Time and Date structs

Using a pointer (or reference) to the variable in the declaration, rather than just declaring it as a normal variable, means that you can manipulate it more easily. For example, to print an ASCII representation of the current date and time, you use code such as:

time_t now;
struct tm * time_info;
        // Declared as a pointer to struct tm

time ( &now ); // Pass by reference

time_info = localtime ( &now );
       // Return pointer to struct tm

printf ( "Current date/time : %s\n",
        asctime ( time_info ));

Pointers are covered in detail in the next chapter. They are essentially just references to the places in memory where the data types are stored. If you had declared time_info in the previous snippet a ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required