There are, of course, times when someone presents you with an impromptu topic and you have to address the question. They will happen throughout your lifetime. But, the good news is that with more life experience you will be able to handle these questions with greater ability.
On the other hand, there are those who really enjoy asking questions that are "off the cuff" for roughly the same reason surprise parties exist: to see how you handle the situation. It is true that how you handle the "situation" reveals quite a bit about who you are and how you solve problems. But, there are times when you have no desire at all to have folk "prying" around inside your brain just so they can see what makes you tick.
If you like putting your best foot forward, then you should join me in thinking that impromptu topics are extremely dangerous. Especially in such situations as job interviews, new and important relationships and important unusual situations. The question is simple: "In this situation, how can I appear to be better than I really am." The least you can hope for is, "I don't want this situation to make me appear less competent than I really am."
So, how should the impromptu situation be handled? Anticipation: thinking and planning ahead is a habit of successful people. You should be able to anticipate many impromptu topics and then prepare for the occasion. The more you can anticipate the better your chances of appearing to be "brighter and more intelligent" than you really are.
Plan (outline and rehears) the content of your response to each impromptu question you can anticipate. Know what content you will use to address the topic that appears suddenly. Don't plan the words, but instead follow the same path you would if you had ample time to prepare your address. In short, you should prepare an extemporaneous speech in which you have the content under control and you choose the words needed at the time you answer the question.
Avoid making impromptu speeches whenever possible and in place of them give appropriate extemporaneous speeches. You'll be ahead of the game.