Can I do arithmetic on void * pointers in C?

后端 未结 6 551
攒了一身酷
攒了一身酷 2020-12-03 14:45

is this valid

void *p = &X; /* some thing */
p += 12;

and if so what does p now point to? I have (third party) code that does this (an

6条回答
  •  攒了一身酷
    2020-12-03 14:57

    Your guess is correct.

    In the standard ISO C99, section 6.2.5 paragraph 26, it declares that void pointers and character pointers will have the same representation and alignment requirements (paraphrasing).

提交回复
热议问题