cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
Beginners
c++ const_cast
c++ const_cast
Aug 27, 2016 at 4:02pm UTC
danciu
(16)
Why the statement below print one address and two values:
#include <iostream>
using namespace std;
int main() {
const int i = 2147483646;
int *j = const_cast<int*>(&i); // Preferred
*j = 2147483647;
cout << i <<endl<<*j <<endl<<endl;
cout <<&i <<endl<<j <<endl;
}
Thank's whom will answer.
All the best
Last edited on
Aug 27, 2016 at 4:02pm UTC
Aug 27, 2016 at 4:41pm UTC
JLBorges
(13770)
Undefined behaviour.
Except that any class member declared
mutable
can be modified,
any attempt to modify a
const
object during its lifetime results in undefined behaviour. - IS
undefined behaviour
: Renders the entire program meaningless
http://en.cppreference.com/w/cpp/language/ub
Aug 29, 2016 at 8:55am UTC
danciu
(16)
Thank you very much!
Topic archived. No new replies allowed.