I\'ve just started learning C and I\'ve been running some simple programs using MinGW for Windows to understand how pointers work. I tried the following:
In the first example, ptr has not been initialized, so it points to an unspecified memory location. When you assign something to this unspecified location, your program blows up.
In the second example, the address is set when you say ptr = &q, so you're OK.