这会导致悬空指针吗?

象嘉道*_*象嘉道 0 c pointers dangling-pointer

这样的函数会导致悬空指针吗?

int *foo () {
    int a[2] = {2, 3};
    int *p = NULL;
    p = a;
    return p;
}
Run Code Online (Sandbox Code Playgroud)

Ed *_* S. 6

是.您将返回指向具有自动存储持续时间的阵列的指针.当函数返回时指针无效.