Challenge - 5 Problems
Basic 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 float operations
What is the output of this C code snippet?
C
#include <stdio.h> int main() { int a = 5; float b = 2.0; printf("%f", a / b); return 0; }
Attempts:
2 left
💡 Hint
Remember that dividing an int by a float results in a float.
✗ Incorrect
The integer 'a' is promoted to float during division, so 5 / 2.0 equals 2.5, printed as 2.500000.
❓ Predict Output
intermediate2:00remaining
Size of data types
What will this program print?
C
#include <stdio.h> int main() { printf("%zu", sizeof(char) + sizeof(int)); return 0; }
Attempts:
2 left
💡 Hint
On most systems, char is 1 byte and int is 4 bytes.
✗ Incorrect
sizeof(char) is 1 byte, sizeof(int) is usually 4 bytes, so total is 5 bytes. But on 64-bit systems, int is 4 bytes, so sum is 5 bytes. However, the output is 5, not 8. This means option D is incorrect. We must check carefully.
❓ Predict Output
advanced2:00remaining
Unsigned integer overflow behavior
What is the output of this code?
C
#include <stdio.h> int main() { unsigned int x = 0; x = x - 1; printf("%u", x); return 0; }
Attempts:
2 left
💡 Hint
Unsigned integers wrap around on underflow.
✗ Incorrect
Subtracting 1 from 0 in unsigned int wraps to the maximum unsigned int value, which is 4294967295 on 32-bit systems.
❓ Predict Output
advanced2:00remaining
Character and integer conversion
What does this program print?
C
#include <stdio.h> int main() { char c = 'A'; int i = c + 1; printf("%c %d", i, i); return 0; }
Attempts:
2 left
💡 Hint
Characters are stored as numbers internally.
✗ Incorrect
'A' has ASCII code 65, adding 1 gives 66 which is 'B'. So it prints 'B 66'.
🧠 Conceptual
expert2:00remaining
Behavior of signed integer overflow
What happens when a signed int variable in C overflows?
Attempts:
2 left
💡 Hint
Signed integer overflow is not defined by the C standard.
✗ Incorrect
Signed integer overflow in C is undefined behavior, meaning the program may behave unpredictably.