In the first one, you're never reserving any memory for p to point to, nor are you pointing it to memory you already have.
Line 2 in the program that crashes is like pointing to an empty space or to a bookshelf and saying "paint that car blue". You need to remember that computers have no imagination. ;)