4.17
#include<iostream>
int main()
{
using namespace std;
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 ";
cout << "value = " << *pd << ": location = " << pd << endl;
cout << "location of pointer pd: " << &pd << endl;
cout << "size of pt = " << sizeof(pt);
cout << ": size of *pt = " << sizeof(*pt) << endl;
cout << "Size of pd = " << sizeof pd;
cout << ": sizet of pd = " << sizeof(*pd) << endl;
system("pause");
return 0;
}
4.18
#include<iostream>
int main()
{
using namespace std;
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 = p3 + 1;
cout << "Now p3[0] is " << p3[0] << " and ";
cout << "p3[1] is " << p3[1] << ".\n";
p3 = p3 - 1;
delete[] p3;
system("pause");
return 0;
}