The Rambam (Rabbi Moshe Maimonides, Spain-Egypt, 1135-1204), in his Hilchot Talmud Torah (chapter 4), presents a number of laws governing questions that one poses to his Rabbi (listen to audio recording for precise citation). First, the Rambam writes that a student should not ask his Rabbi a question that does not pertain to the subject matter currently being learned. Since the Rabbi may not always immediately have the correct answer to questions regarding a subject he is not currently teaching, posing such a question may cause him embarrassment and should therefore not be asked.
The source for this Halacha is a story told in the Gemara (Shabbat 3) about Rav, who once posed a question to his Rabbi, Rabbi Yehuda Hanasi, about a different subject than the material studied. Rabbi Yehuda answered the question correctly, but Rabbi Hiya then commented to Rav that he should not have asked such a question to Rabbi Yehuda. Since Rabbi Yehuda was an exceptionally great Torah scholar, it turned out that he knew the answer, but other Rabbis may not be able to answer and would thus suffer embarrassment.
The Rambam adds that this Halacha applies only to students asking their Rabbis. A Rabbi, however, may ask his students questions from other areas of Torah than the one being studied in order to motivate them in their learning. Rabbis may wish to ask questions for the sake of review, to test their memory or to get the students to think. This is entirely permissible as an educational method, even though a student should not ask his Rabbi a question that is not pertinent to the subject matter at hand.
The Rambam also writes that students should not approach their Rabbi with questions immediately upon his entry into the study hall. They should rather wait and allow him to unwind, so-to-speak, so that he will be in a proper frame of mind to listen and respond to their questions.
Summary: It is improper for students to ask their Rabbi a question that does not relate to the material under discussion, as he will be embarrassed if he does not know the answer. Students should not ask their Rabbi questions when he comes into the study hall until after he has had a moment to get settled and in the proper frame of mind.