I know that a NULL pointer is (void*)0
Not necessarily. The macro NULL could be defined as 0
, (void*)0
or something else. The only requirement is that it is compatible with a null pointer for the specific implementation. In theory, a compiler could define NULL as 1, but in practice nobody does that.
Is NULL guaranteed to be implicitly converted to the type on the left
Yes, any expression where a null pointer is used together with another kind of pointer yields a null pointer. This has nothing to do with some implementations defining NULL as (void*). The C standard simply guarantees null pointer conversions, no matter the NULL macro.
in C, the type returned by malloc() is void* but is implicitly converted to the type of the lvalue?
Yes, in C a void*
will always be implicitly converted to/from a pointer of another type (in C++, you would however need an explicit cast).