There are many typescasting types to ensure that assignment operations such as implicit type conversion (forward) and explicit type conversion (truncation), but I'm not sure how this works for pointer type conversion for a ternary operator.
#include <stdlib.h>
int main (void)
{
(void)((rand() ? (char*)NULL : NULL) + 1);
(void)((rand() ? (char*)NULL : (void*)NULL) + 1);
return 0;
}
Apparently, the compiler treats the expression A as a type char*, and B as a type void*.
I have two questions:
I checked the pre-processed code, and NULLexactly grown up ((void*)0), so why ((void*)0)and (void*)((void*)0)different types?
According to expression B, why does the compiler apply a type char*to a type void*, but not vice versa?