← Quiz: Type Casting in C++: all 10 questions
Quiz: Type Casting in C++ · Question 5 of 10
What does this print? (code)
What does this print?
#include <iostream>
using namespace std;
int main() {
double d = 9.99;
int i = static_cast<int>(d);
char c = static_cast<char>('a' + i);
cout << i << " " << c << "\n";
return 0;
}
- A.10 k
- B.9 j
- C.9 i
- D.10 j
Answer & explanation
Correct answer: 9 j
Converting 9.99 to int truncates to 9, and 'a' + 9 is 'j'.
Can you get the rest right without peeking?
Take the timed Quiz: Type Casting in C++ quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →