Challenge - 5 Problems
Built-in Data Types Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of integer and floating-point operations
What is the output of the following C++ code?
C++
#include <iostream> int main() { int a = 5; double b = 2.0; std::cout << a / b << std::endl; return 0; }
Attempts:
2 left
💡 Hint
Remember that dividing an int by a double results in a double.
✗ Incorrect
The integer 5 is promoted to double 5.0, then divided by 2.0, resulting in 2.5.
❓ Predict Output
intermediate2:00remaining
Size of built-in data types
What is the output of this C++ code on a typical 64-bit system?
C++
#include <iostream> int main() { std::cout << sizeof(char) << "," << sizeof(int) << "," << sizeof(long long) << std::endl; return 0; }
Attempts:
2 left
💡 Hint
On most 64-bit systems, char is 1 byte, int is 4 bytes, and long long is 8 bytes.
✗ Incorrect
The sizes reflect typical memory allocation: char=1 byte, int=4 bytes, long long=8 bytes.
🧠 Conceptual
advanced2:00remaining
Understanding signed and unsigned integer behavior
What will be the output of this C++ code snippet?
C++
#include <iostream> int main() { unsigned int x = 0; std::cout << x - 1 << std::endl; return 0; }
Attempts:
2 left
💡 Hint
Unsigned integers wrap around when subtracting beyond zero.
✗ Incorrect
Subtracting 1 from 0 in unsigned int wraps to the maximum value (2^32 - 1 = 4294967295).
❓ Predict Output
advanced2:00remaining
Boolean type and implicit conversion
What is the output of this C++ code?
C++
#include <iostream> int main() { bool flag = 5; std::cout << flag << std::endl; return 0; }
Attempts:
2 left
💡 Hint
Any non-zero integer assigned to a bool becomes true (1).
✗ Incorrect
In C++, bool stores either 0 (false) or 1 (true). Assigning 5 converts to true (1).
🔧 Debug
expert2:00remaining
Identify the error in this code using built-in types
What error does this C++ code produce when compiled?
C++
#include <iostream> int main() { int x = 10; double y = 3.5; int z = x / y; std::cout << z << std::endl; return 0; }
Attempts:
2 left
💡 Hint
Division of int by double results in double, then assigned to int truncates the decimal.
✗ Incorrect
x / y is 10 / 3.5 = 2.857..., assigned to int z truncates to 2, no errors occur.