You can learn a lot about someone in situations like this (even if the interviewer KNEW you were right). However ethical this may or may not be on the part of the interviewer there IS a lot of insight they can learn from this rather than just Q/A over mindless trivia.
Consider:
- How does the candidate react when others inaccurately tell him he is incorrect? Is he a team player or a "my way or the highway" type person?
- How well does the candidate understand why his answer is correct? Does he have a deep understanding over the material/question or just know it without understanding why?
- How does the candidate react to conflict?
Conflict and disagreement comes up all the time in the working world. Being able to deal with things in a mature way is important.
Is there any polite way of handling such situations?
The polite way is however you would react to someone on your team similarly disagreeing. A statement like, "I understand we disagree on this issue. Is there any chance we can <INSERT_PHRASE_HERE> and move forward?"
That phrase could be any of the following depending on the tone of the interview:
- Research via Google at the end of the interview, time permitting
- Followup with email
- Determine if this particular question is a show stopper
- Agree to disagree until you've both had a chance to look things up and verify your positions
- etc
How can I tell him "you are wrong" or "let's check it in the IDE right now" without sounding arrogant?
This would be more difficult. You could suggest something along the lines of, "I understand we disagree - if this was in the course of our normal work I would recommend we look at this over an IDE and determine what our disagreement is. However, this is likely not possible at this time - is there any chance we can move forward?"
You do not want to leave the interviewer the impression of you being condescending or arrogant (unless you are so ridiculously qualified and competent you feel this won't matter?). Nor do you want them feeling you are argumentative for the sake of being argumentative. Pulling up an IDE and going "hah! I was right!" does not exactly bode well for leaving a positive impression on the interviewer in most cases.
The best end result is the interviewer feeling your are competent and confident in your own abilities but able to resolve conflict in a meaningful fashion (especially if they are being intentionally argumentative).
As an aside, sometimes this sort of dialogue can be quite revealing about whether you actually understand material and the subject being asked about rather than just the surface level answer. Imagine a question like
How is std::vector implemented?
If you answer "with an array" your interviewer might be able to go "correct!" but if they disagree and you start discussing why it is or why it makes sense to be, they learn a lot more about your understanding of lookup times, copy times, and all the other factors which go into why std::vector is implemented the way it is implemented. Just by disagreeing with you.
Now imagine if instead they say "no" and you respond "no, really, it is, let's look it up" instead of dialoguing about the why - you lose this opportunity to talk about your answer's justification and show deeper understanding of the above ideas. Additionally, your interviewer may go "oh this guy doesn't really understand why std::vector is done the way it is but just knows it is."
This somewhat assumes your interviewer is attempting to adequately interview you to determine your abilities. Sometimes you just will have a bad interviewer, in which case all bets are off...