Does the following code make p as a null pointer
static int *p;

since printf("%u",p);

outputs as 0

though the syntax is int *p=NULL or int *p=0

Recommended Answers

All 2 Replies

Use %p for pointers.

Does the following code make p as a null pointer

Yes. Static variables are zero initialized, which for pointers means the equivalent of NULL. You can verify that this is the case (other than reading the standard documentation) with a simple test:

#include <stdio.h>

static int *p;

int main(void)
{
    if (p == NULL)
        puts("It's NULL!");

    printf("Zero initialized address: %p\n", (void*)p);

    return 0;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.