Question: I had been writing things like 

```
char *x=NULL;

```

on the assumption that 

```
 char *x=2;

```

would create a `char` pointer to address 2. 

But, in [The GNU C Programming Tutorial](http://www.crasseux.com/books/ctutorial/Pointers-and-initialization.html#Pointers%20and%20initialization) it says that `int *my_int_ptr = 2;` stores the integer value `2` to whatever random address is in `my_int_ptr` when it is allocated.

This would seem to imply that my own `char *x=NULL` is assigning whatever the value of `NULL` cast to a `char` is to some random address in memory.

While

```
#include <stdlib.h>
#include <stdio.h>

int main()
{
    char *x=NULL;

    if (x==NULL)
        printf("is NULL\n");

    return EXIT_SUCCESS;
}

```

does, in fact, print 

> 
> is NULL
> 
> 
> 

when I compile and run it, I am concerned that I am relying on undefined behavior, or at least under-specified behavior, and that I should write

```
char *x;
x=NULL;

```

instead.

Answer: 
To clarify why the tutorial is wrong, `int *my_int_ptr = 2;` is a "constraint violation", it is code which is not allowed to compile and the compiler must give you a diagnostic upon encountering it.

As per 6.5.16.1 Simple assignment:

> 
> Constraints 
> 
> 
> One of the following shall hold:
> 
> 
> * the left operand has atomic, qualified, or unqualified arithmetic type, and the right has arithmetic type;
> * the left operand has an atomic, qualified, or unqualified version of a structure or union type compatible with the type of the right;
> * the left operand has atomic, qualified, or unqualified pointer type, and (considering the type the left operand would have after lvalue
>  conversion) both operands are pointers to qualified or unqualified
>  versions of compatible types, and the type pointed to by the left has
>  all the qualifiers of the type pointed to by the right;
> * the left operand has atomic, qualified, or unqualified pointer type, and (considering the type the left operand would have after lvalue
>  conversion) one operand is a pointer to an object type, and the other
>  is a pointer to a qualified or unqualified version of void, and the
>  type pointed to by the left has all the qualifiers of the type pointed
>  to by the right;
> * the left operand is an atomic, qualified, or unqualified pointer, and the right is a null pointer constant; or
> * the left operand has type atomic, qualified, or unqualified \_Bool, and the right is a pointer.
> 
> 
> 

In this case the left operand is an unqualified pointer. Nowhere does it mention that the right operand is allowed to be an integer (arithmetic type). So the code violates the C standard.

GCC is known to behave poorly unless you explicitly tell it to be a standard C compiler. If you compile the code as `-std=c11 -pedantic-errors`, it will correctly give a diagnostic as it must do.
I would like to add something orthogonal to the many excellent answers. Actually, initializing to `NULL` is far from bad practice and may be handy if that pointer may or may not be used to store a dynamically allocated block of memory.

```
int * p = NULL;
...
if (...) {
    p = (int*) malloc(...);
    ...
}
...
free(p);

```

Since according to the [ISO-IEC 9899 standard](http://www.open-std.org/JTC1/SC22/wg14/www/docs/n1124.pdf) `free` is a nop when the argument is `NULL`, the code above (or something more meaningful along the same lines) is legit.