Different Pointer Arithmetic Results when Taking Address of Array

后端 未结 5 2078
北恋
北恋 2020-12-25 10:14

Program:

#include

int main(void) {
    int x[4];
    printf(\"%p\\n\", x);
    printf(\"%p\\n\", x + 1);
    printf(\"%p\\n\", &x);
    p         


        
5条回答
  •  眼角桃花
    2020-12-25 10:29

    An easy thumbrule to evaluate this is:

    Any pointer on increment points to the next memory location of its base type.

    The base type of &x here is int (*p)[4] which is a pointer to array of 4 integers.

    So the next pointer of this type will point to 16 bytes away (assuming int to be 4 bytes) from the original array.

提交回复
热议问题