I am confused from something.
first:
int *ptr;
ptr = malloc(10 * sizeof(int));
This type of getting dynamic(heap) memory at run-time, not compile time like arrays.
malloc() may be return NULL if there is no memory.
And NULL is a #define in Standard C Library #define NULL ((void *)0)
So, if the malloc return NULL and it executes at run-time, how the compiler will substitute NULL with void *0 and I know that any text substitution happen in pre-compile phase
No, you have it wrong. Imagine the
mallocfunction something like this:The compiler replaces
NULLwhen that translation unit is compiled, i.e. when the standard library is compiled so no trace ofNULLsurvives past the preprocessor phase. After that point, for what it’s worth, malloc just returns numbers.