CJCoding With Joseph
15free / daySign inCreate account
← Back to Question List
C++ Code Walkthrough #47

static_cast Between Numbers and Characters

mediumCasting

📄 Code

Read carefully — what does this print?
1#include <iostream>
2using namespace std;
3 
4int main() {
5 cout << static_cast<int>(3.99) << " " << static_cast<int>(-3.99) << endl;
6 cout << static_cast<char>(66) << static_cast<char>(67) << endl;
7 cout << static_cast<int>('a') << " " << static_cast<bool>(0.0) << static_cast<bool>(-2) << endl;
8 cout << 10 / 4 * 2.0 << " " << 10 / 4.0 * 2 << endl;
9 return 0;
10}

🎯 Your Answer