pointer default value .?

Pointers have no default value. The value they have is just whatever junk was in the memory they’re using now. Sometimes a specific compiler will zero out memory, but that’s not standard so don’t count on it.)

The memory from malloc being NULL was a coincidence; it could have been any other value just as easily. You need to and should always manually set all your pointers to NULL.

Another alternative is you can also use calloc, which does the same thing as malloc but sets all bits to 0 in the block of memory it gives you. This doesn’t help with stack variables though, so you still have to set those to NULL by yourself.

Leave a Comment