Reading this Q&A, I thought p shouldn't be a nullptr even if x is 0. Have I understood it right?
int main()
{
int x = 0;
std::cin >> x; // Enter `0`
void *p = (void *)x; // or: void *p = reinterpret_cast<void*>(x);
if (!p)
std::cout << "p is nullptr" << std::endl;
}
After entering 0 in the standard input, the message p is nullptr will be shown in my GCC.
According to the link, it shouldn't evaluate to nullptr, but the result is not as my expectation.
Is the code undefined behavior? or unspecified result? Why does it evaluate to nullptr?