The Rambam (a”h), in Hilchot Talmud Torah, presents a number of laws governing questions that one poses to his Rav. First, 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 halachah is brought down in the Gemara of Shabat concerning a story about Rav, who once posed a question to his Rabbi, Rabbi Yehudah Ha’nasi. The question was about a different subject than the material studied. Rabbi Yehudah answered the question correctly, but Rabbi Chiyah then commented to Rav that he should not have asked such a question. Since Rabbi Yehudah was an exceptional talmid chacham, it turned out that he knew the answer, but other Rabbis may not be able to answer and would therefore suffer embarrassment.
The Rambam adds that this halachah 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 that he will be in a proper frame of mind to listen and respond to their questions.