Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main()
- {
- const int i = 9;
- const_cast<int&>(i) = 6; // changing cost value
- int j;
- static_cast<const int&>(j); // casting static to const
- const int* p1 = &i;
- int const* p4 = &i;
- cout << p1 << endl;
- *p1++;
- // cout << p1 << endl;
- // 1. When const is on the left of *, data is const
- // 2. If const is on the right of *, pointer is const
- // Why use const
- // a) Guards the value
- // b) Self documenting
- // c) Enable the compiler to do more optimization, making the code tighter
- // d) Const means the variable can be put in ROM; useful for embedded
- }
Add Comment
Please, Sign In to add comment