Compiler specific
Thank you. Yes, this is TOTALLY compiler specific. I have compiled this code with icc, g++ (under Unix), and Dev-C++ (under Windows). All of these compilers generate code which prints 3.1415926 (i.e. alias variable and explicit casting do not change the const variable). Compilers create two INDEPENDENT variables pi=3.1415926 and pi_copy=4.0. I was thinking about migration to Dev_C++, but it has some...
User Profile
Collapse
-
const variable in C++ can be changed using aliases
Hello.
const qualifier is usually posed as better alternative to #define (because it allows to check types). The simple program shows how const variable can be changed in C++
Result of printing of pi will be 4. I used Visual C++ 2010 under Windows XP.Code:const double pi = 3.1415926; double& pi_copy = (double&)pi; pi_copy = 4.0; cout << pi << endl;
As far...
No activity results to display
Show More
Leave a comment: