[Solved] why malloc is returing o as default in gcc compiler? [closed]


“Freeing” means “making available for allocation again”. There is no automatic deleting / overwriting of memory contents because it would negatively impact performance. If you want the area to be set to a value, you have to do it yourself before you call free(). That would be bad practice in release code, though (for anything else but data security reasons).

The same is true when allocating the memory: It does not get set to any specific value, but contains what it happened to contain previously. If you want it to be initialized to zero, use calloc(). If you want to set it to a specific other value, use memset() after you allocated it. Again, consider that this has performance implications, and is usually not necessary.

As for your last question, "%d" is for signed integers. For unsigned, use "%u".

4

solved why malloc is returing o as default in gcc compiler? [closed]