-
January 29th, 2010, 07:42 AM
#1
const_cast does not modify variables value
const int z = 10;
const int *x = &z;
*const_cast <int *> (x) = 1;
const int &ref = z;
const_cast<int &> (ref) = 15;
cout<< "z= " << z;
cout <<"*x ="<<*x;
cout << "ref = "<<ref;
Output seen
z = 10
*x = 15;
ref = 15
how can z be 10 if its reference and value at its address is 15. is a separate copy of z kept ?
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|