Q:

'W' prints out W and "W" prints out $. Why?

I'm beginner. I don't know why? I'm using Code::Blocks.Please read the following code:

If q=' W ', it prints out W. 
If q=" W ", it prints out $.

A:

The literal "W" is not a single char, but a null-terminated string consisting of 'W' and '\0'. 
One way to get the desired behaviour by assigning to a const char* and printing that with %s
const char* q = "W";
printf("%s", q);

As pointed out in comments, you could catch this type of error by increasing your compiler's warning levels.

A:

Statement
char q = "W";

takes an address of string literal "W", and casts the value of the address to char, i.e., the least significant byte of the address is assigned to c. 
In your case, the address of "W" could be e.g. 0x12345624, and it is cast to 0x24, that is '$'.

