You don't check the value of a
. (BTW, why do you cast the return value?)
I suppose it is NULL
. So a write access to a[0]
is no valid C, but it might (depending on the architecture) work nevertheless - and cause havoc and disruption there.
The compiling process works as expected, because for the compiler and the linker, malloc()
is a function as anything else. The mistake only happens at runtime.