Using the const and volatile variable in C++ program


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)

Other info:

To do: Declaring and using the const and const volatile in C++ program

To show: The const and volatile keyword usage in C++ program to declare the const volatile variable





// Demonstrates the type casting

#include <iostream>

using namespace std;


class One



void funct()




// const and volatile...

const volatile int* Test1;


// const...

const int* Test2;


void TestConstVol()


One Test3;

// remove const...


// remove const and volatile...

const_cast<int> (Test1);



int main(void)




return 0;



Output example:



Press any key to continue . . .



C and C++ Programming Resources | C & C++ Code Example Index