Home > Back-end >  [questions] a little bit of small problems about pointer address (embedded, C)
[questions] a little bit of small problems about pointer address (embedded, C)

Time:11-26

The static unsigned char xdata membuff [256].
The static unsigned char * p;

P=& amp; Membuff;

Printf (" membuff address: % p \ n ", membuff);
Printf (" p: % 4 x \ n ", p);

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Print results: membuff address: x: 010 b
P: 0101
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Question: why not storing the addresses of the membuff p?

After change printf parameters to % p:


Printf (" membuff address: % p \ n ", membuff);
Printf (" p: p \ % n, p);

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Print results: membuff address: x: 010 b
P: x: 010 b
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Question: % p print is not the pointer p address? Why become a membuff first address?

CodePudding user response:

% p type is a pointer variable p content, namely membuff address,
As to use % % x and the difference between the output of the p, didn't see it, but it's important to note that x % and % p print length may be different, for example, in 64 for the system, x % print is 4 bytes address, and % p output is 8 bytes address,