No, the arrangement and padding (and even the existence) of variables on the stack is implementation-dependent, and what you have here is Undefined Behavior. The language specifies that you must not use a pointer to access the memory of any object other than the one it points to.
In this case, &xc + 1
points to memory that lies outside the allocation of xc
. You cannot read or write to this location and expect any kind of predictable result. Note that it is actually a valid pointer -- you are allowed to point "one-past-the-end" of an allocation, provided you never dereference that address.
To explain what's actually happening in your case: your variables are being pushed onto the stack, and the stack memory extends in the direction of lower addresses. That said, even this program on your computer with your compiler does not guarantee this behavior. The original variable x
could be optimized away by the compiler completely because it is not used. The compiler is not required to understand that you're aliasing x
via xc
because, as already mentioned such behavior is not defined.