A pointer to a const variable
Compiler: Visual C++ Express Edition 2005
Compiled on Platform: Windows XP Pro SP2
Header file: Standard
Additional project setting: Set project to be compiled as C++
Project -> your_project_name Properties -> Configuration Properties -> C/C++ -> Advanced -> Compiled As: Compiled as C++ Code (/TP)
To do: Display some strings
To show: A pointer to a const variable
// A pointer to a const variable
using namespace std;
const char *BuffOne = "Testing";
cout<<"The data pointed by BuffTwo is "<<BuffOne<<endl;
// The const pointer BuffOne assigned to the const pointer ThePtr is OK...
const char *ThePtr = BuffOne;
cout<<"The data pointed by ThePtr is "<<ThePtr<<endl;
// The following code will generate an error, cannot modify the const....
// *ThePtr = 'z';
The data pointed by BuffTwo is Testing
The data pointed by ThePtr is Testing
Press any key to continue . . .