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.
Exercise: Quotation marks 1
Exercise: Quotation marks 2
Related topic:
MLA citation ending in a question mark or exclamation point