C Programming – Reasons to Assign NULL Instead of 0 to Non-Pointer Variables

cnull

Assigning variables with values during definition is a good practice.

A common practice is to assign variables with 0 and pointers with NULL.

    int p = NULL; // instead of int p = 0;
    int *ptr = NULL;
    int &ref=p;

Are there reasons to assign NULL instead of 0 to a non-pointer variable type? The int p = NULL code compiles in Visual Studio, but it seems it may be less readable than assigning to zero.

Best Answer

The macro NULL is a null-pointer constant and has either an integer type or a pointer type.

Using NULL to assign or initialize a non-pointer variable will lead to question marks from other programmers at the least and it might result in compiler failures.
A line like

int a = NULL;

is not considered good code and it will make the code less readable.