I couldn't find in the C standard, if uninitialized pointers evaluate to true, false, or result in undefined or implementation defined behavior? For example:
{
int *p;
if (p)
do_sth();
}
I couldn't find in the C standard, if uninitialized pointers evaluate to true, false, or result in undefined or implementation defined behavior? For example:
{
int *p;
if (p)
do_sth();
}
In your sample code it's undefined behavior to access any uninitialized values in C, regardless of its type (except for unsigned char
).
Since a pointer is not a unsigned char
type, the behavior is undefined.
Note for implicit initialization, like putting the definition in file scope, or defining it with static
storage class specifier, causes the object to be zero-initialized by default.
For more information, see (Why) is using an uninitialized variable undefined behavior?