Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using std::cout;
- using std::endl;
- int main() {
- int *x;
- {
- // n become alive here
- int n = 5;
- // Get the address of n
- int* y = &n;
- // Share the address of n to x
- x = y;
- } // n lives until here
- // Now, assess n, which is no longer alive
- // The behavior is undefined.
- cout << *x << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement