Different Pointer Arithmetic Results when Taking Address of Array

后端 未结 5 2084
北恋
北恋 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:40

    Believe it or not, the behaviour of your program is undefined!

    &x + 1 is actually pointing to just beyond the array, as @i486's answer cleverly points out. You don't own that memory. Even attempting to assign a pointer to it is undefined behaviour, let alone attempting to dereference it.

提交回复
热议问题