The following code (taken from here):
int* ptr = int();
compiles in Visual C++ and value-initializes the pointer.
How is that possible? I mean int()
yields an object of type int
and I can't assign an int
to a pointer.
How is the code above not illegal?
int()
is a constant expression with a value of 0, so it's a valid way of producing a null pointer constant. Ultimately, it's just a slightly different way of sayingint *ptr = NULL;