COMP2113
COMP2113_ENGG1340 Programming technologies and Computer programming II [Section 2BC] [2023]
Loading...
Searching...
No Matches
pointer_date.cpp
Go to the documentation of this file.
1#include <iostream>
2#include <iomanip>
3using namespace std;
4
5struct Date
6{
7 int day;
8 int month;
9 int year;
10};
11
12int main()
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 main()
int year
int month
int day