🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← 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;
}
  1. A.10 k
  2. B.9 j
  3. C.9 i
  4. 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 →