Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main()
- {
- int x = 2;
- int *ptr = &x;
- (*ptr)++;
- cout << (*ptr);//prints out 3
- }
- VS
- #include <iostream>
- using namespace std;
- int main()
- {
- int x = 2;
- int *ptr = &x;
- ptr++;
- cout << (*ptr); //undefined behavior, prints out what ever is in the memory spot after the address of x, which could be anything
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement