Does p-- point to b in this code, or is the behavior undefined?
I am trying to understand whether the following C++ program has well-defined behavior. #include <bits/stdc++.h> using namespace std; int main() { int a = 15, b = 10; int *p = &a, *q = &b; *p-- += b ^ ~--a; *p += 2; cout << a << ", " << b; } My question is not primarily about the program's output, but about what p points to after p--. Since p initially points to a, after the expression *p-- += b ^ ~--a; p is decremented. Does C++ guarantee that p will then point to b, assuming a and b are local variables declared one after the other? Or does p point to an unrelated memory location, making the n
0 upvotes
View original discussion ↗
Comments
Sign in or sign up to comment and upvote.
No comments yet.