开发者

Clarfication on pointer arithmetic

*(*(p+a)+b)

If a*size is added to an address (p), then why is b*size added to *(p+a)? *(p+a) appears to b开发者_StackOverflow社区e the value at that location and adding b*size to it would change its value, not the address. However, based on what I read this is meant to be added to an address.


Given your expression, and assuming you're talking about C, p must be a pointer to a pointer. What happens is:

char ** p;
int a = 2;
int b = 4;

(p+a) // adds 2 * sizeof(char *)
*(p+a) // evaluates to a char *
char * c = *(p+a)
(c+b) // adds 4 * sizeof(char)
*(c+b) // evaluates to a char
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜