Why does this C pointer's deferenced value become its memory address -
wondering why when function below runs, *p , p printed out having same value. understanding when *p++ runs, causes address of p increment one, why cause *p become memory address.
i tried running code without *(just p++) , output still same, significance of * in demo code lecture.
the output i'm getting is:
1606416248 1606416248
int main() { int *p; int = 4; p = &a; *p++; printf("%d %u\n", *p, p); }
first of all, %u improper format specifier printing address. should use %p printing address, , cast argument (void *) . alone sufficient invoke undefined behavior.
then coming to
but why cause *p become memory address.
when *p++;, you're running out of bound, p points single variable, not array. so, next dereference of pointer *p, invalid memory access, causing ub. output, thereafter cannot justified in way.
Comments
Post a Comment