Type Casting Between Data Types
C++
Easy
7 views
Problem Description
Convert values from one data type to another (implicit andexplicit). This teaches type conversion and data loss concepts.
Logic: Use cast operators to convert between types
Official Solution
void question2_type_casting() {
int intNum = 10;
float floatNum = 3.14;
char ch = 'A';
float result1 = intNum + floatNum; // Implicit casting
int result2 = (int)floatNum; // Explicit casting
int asciiValue = (int)ch;
cout << "Int + Float = " << result1 << endl;
cout << "Float to Int = " << result2 << endl;
cout << "Char to ASCII = " << asciiValue << endl;
}
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!