Important MCQ

Which is the correct way to read an integer n?

Q.Which is the correct way to read an integer n?

A) cin << n;
B) cin >> n;
C) cin = n;
D) cout >> n;
Correct Answer:
Option B
Detailed Explanation:
B) cin >> n; is correct. cin is an istream object used for keyboard input with >>. It can read multiple values separated by whitespace; getline reads a complete line including spaces.