2022-02-16

Is computing a pointer to uninitialized memory undefined behavior in C?

If I understand correctly, this programme has undefined behavior in C++ because the intermediate value p + 1 is a pointer to uninitialized memory:

int main () {
    int x = 0;
    int *p = &x;
    p = p + 1 - 1;
    *p = 5;
}

If void were put in main's argument list (as required by the C grammar), would it also be undefined behavior in C?



from Recent Questions - Stack Overflow https://ift.tt/68PlTvr
https://ift.tt/2seQpNE

No comments:

Post a Comment