Home > Back-end >  C pointer problem
C pointer problem

Time:09-26

Thank you bosses first! There are two problems:

1. Define variables, in memory address should be continuous, why is the address of the p + 4 b instead of p + 1

2. What is more, if the b before addressing, & amp; B, then b address again become p - 1.,,, what the hell!

CodePudding user response:

Type a, b, is on the stack, look from your log, the stack is downwards, address is the address of a b - 4, p - 1, neither is p + 4, also won't be p + 1; You print * (p + 4) is equal to 300, is more of a coincidence,
You can further track, 300 which is to take a look at this

CodePudding user response:

The same function of the variables in memory location and order statement is not nothing to do with the stack grows direction
Crossing the line is undefined behavior
Don't expect to rely on the features of pointer to run

CodePudding user response:

Continuous address, you'll need to find such a pointer array in accordance with your request

CodePudding user response:

Thank you bosses answer

CodePudding user response:

Int type of 4 bytes,
The compiler
  • Related