0
0
C++programming~20 mins

Built-in data types in C++ - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Built-in Data Types Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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;
}
A2
B2.50
C2.5
D2.0
Attempts:
2 left
💡 Hint
Remember that dividing an int by a double results in a double.
Predict Output
intermediate
2: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;
}
A1,4,8
B1,8,8
C1,4,4
D2,4,8
Attempts:
2 left
💡 Hint
On most 64-bit systems, char is 1 byte, int is 4 bytes, and long long is 8 bytes.
🧠 Conceptual
advanced
2: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;
}
A4294967295
B0
C-1
DCompilation error
Attempts:
2 left
💡 Hint
Unsigned integers wrap around when subtracting beyond zero.
Predict Output
advanced
2: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;
}
A5
B1
Ctrue
D0
Attempts:
2 left
💡 Hint
Any non-zero integer assigned to a bool becomes true (1).
🔧 Debug
expert
2: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;
}
ANo error, output is 3
BCompilation error: cannot assign double to int
CRuntime error: division by zero
DNo error, output is 2
Attempts:
2 left
💡 Hint
Division of int by double results in double, then assigned to int truncates the decimal.