COMP2113
COMP2113_ENGG1340 Programming technologies and Computer programming II [Section 2BC] [2023]
Loading...
Searching...
No Matches
pointer_date.cpp File Reference
#include <iostream>
#include <iomanip>
Include dependency graph for pointer_date.cpp:

Go to the source code of this file.

Classes

struct  Date
 

Functions

int main ()
 

Function Documentation

◆ main()

int main ( void )

Definition at line 12 of file pointer_date.cpp.

13{
14 Date today = { 26, 2, 2015 };
15
16 cout << setfill('0');
17
18 // access structure member using the dot operator
19 cout << setw(2) << today.day << '/'
20 << setw(2) << today.month << '/'
21 << setw(4) << today.year << endl;
22
23 Date * dPtr = &today; // dPtr now points to today
24
25 // access structure member using the dereference operator and dot operator
26 cout << setw(2) << (*dPtr).day << '/'
27 << setw(2) << (*dPtr).month << '/'
28 << setw(4) << (*dPtr).year << endl;
29
30 // access structure member using the member of pointer shorthand
31 cout << setw(2) << dPtr->day << '/'
32 << setw(2) << dPtr->month << '/'
33 << setw(4) << dPtr->year << endl;
34
35
36 return 0;
37}
int year
int month
int day

References Date::day, Date::month, and Date::year.