-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaddress.cpp
62 lines (48 loc) · 1.37 KB
/
address.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <iostream>
int main()
{
using namespace std;
int donuts = 6;
double cups = 4.5;
cout << "donuts value = " << donuts;
cout << " and donuts address = " << &donuts << endl;
cout << "cups value = " << cups;
cout << " and cups address = " << &cups << endl;
int updates = 6;
int * p_updates;
p_updates = &updates;
cout << "Values: ipdates = " << updates
<< ", *p_updates = " << *p_updates << endl;
cout << "Address: &updates = " << &updates
<< ", p_updates = " << p_updates << endl;
*p_updates += 1;
cout << "Now updates = " << updates << endl;
int nights = 1001;
int * pt = new int;
*pt = 1001;
cout << "nights value = ";
cout << nights << ": location " << &nights << endl;
cout << "int ";
cout << "value = " << *pt << ": location = " << pt << endl;
double * pd = new double;
*pd = 10000001.0;
cout << "double "
<< "value = " << *pd << ": location =" << pd << endl;
cout << "location of pointer pd: " << &pd << endl;
cout << "size of pt = " << sizeof(pt)
<< ": size of *pt = " << sizeof(*pt) << endl;
cout << "size of pd = " << sizeof(pd);
cout << ": size of *pd = " << sizeof(*pd) << endl;
double * p3 = new double [3];
p3[0] = 0.2;
p3[1] = 0.5;
p3[2] = 0.8;
cout << "p3[1] is " << p3[1] << ".\n";
p3 += 1;
cout << "Now p3[0] is " << p3[0] << " and "
<< "p3[1] is " << p3[1] << ".\n";
p3 = p3 -1;
delete [] p3;
cin.get();
return 0;
}