// This example illustrates how the literal constant, "have a nice day" is stored, and how it differs from non-constants.
#include <iostream>
using namespace std;
long long ptr2int(const void* ptr);
int main()
{
int i;
double d;
int* pi;
char* pc;
// addresses of variables and constants
cout << "&i=" << ptr2int(&i) << endl;
cout << "&d=" << ptr2int(&d) << endl;
cout << "&pi=" << ptr2int(&pi) << endl;
cout << "&pc=" << ptr2int(&pc) << endl;
// Why is this address different?
cout << "&\"have a nice day\"=" << ptr2int("have a nice
day") << endl; // What is \"?
cout << "sizeof(\"have a nice day\")=" << sizeof("have a nice day") << endl;
const char* pcc = "have a nice day"; // What does pcc contain?
cout << "pcc=" << pcc << endl;
cout << "&pcc=" << ptr2int(&pcc) << endl;
cout << "sizeof(pcc)=" << sizeof(pcc) << endl;
int contentsof_pcc = ptr2int(pcc);
cout << "contentsof_pcc=" << contentsof_pcc << endl;
// print the contents of "have a nice day"
for (size_t i = 0; i < sizeof("have a nice day"); i++)
cout << static_cast<int>(*(pcc+i)) << " ";
}
long long ptr2int(const void* ptr)
{
return reinterpret_cast<long long>(ptr);
}