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: 
The tutorial is wrong. In ISO C, `int *my_int_ptr = 2;` is an error. In GNU C, it means the same as `int *my_int_ptr = (int *)2;` . This converts the integer `2` to a memory address, in some fashion as determined by the compiler.

It does not attempt to store anything in the location addressed by that address (if any). If you went on to write `*my_int_ptr = 5;`, then it would try to store the number `5` in the location addressed by that address.
`int *my_int_ptr = 2`

> 
> stores the integer value 2 to whatever random address is in my\_int\_ptr when it is allocated.
> 
> 
> 

This is completely wrong. If this is actually written then please get a better book or tutorial.

`int *my_int_ptr = 2` defines an integer pointer which points to address 2. You will most likely get a crash if you try to access address `2`. 

`*my_int_ptr = 2`, i.e. without the `int` in the line, stores the value two to whatever random address `my_int_ptr` is pointing to. Having saying this, you can assign `NULL` to a pointer when it is defined. `char *x=NULL;` is perfectly valid C.

Edit: While writing this I didn't know that integer to pointer conversion is implementation defined behavior. Please see the good answers by @M.M and @SouravGhosh for details.