When question marks and exclamation points apply to the quoted words, put them inside the quotation marks. In the following sentence, the entire question is being quoted, so the question mark appears within the quotation marks.
When question marks and exclamation points apply to the sentence as a whole, put them outside the quotation marks. The following sentence is a question—Have you heard the old proverb?—containing a quotation.
Exercises:
Quotation marks 1
Quotation marks 2
Related topic:
MLA note on a citation ending with a question mark or an exclamation point