Challenge - 5 Problems
Type Modifier Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of signed and unsigned char addition
What is the output of this C code snippet?
C
#include <stdio.h> int main() { signed char a = 127; unsigned char b = 1; int c = a + b; printf("%d\n", c); return 0; }
Attempts:
2 left
💡 Hint
Remember that signed char max is 127 and unsigned char max is 255. The addition promotes both to int.
✗ Incorrect
The signed char 'a' is 127, unsigned char 'b' is 1. Both are promoted to int before addition. 127 + 1 = 128, which fits in int and prints as 128.
❓ Predict Output
intermediate2:00remaining
Effect of long modifier on integer size
What is the output of this C code?
C
#include <stdio.h> int main() { long int x = 2147483648L; printf("%ld\n", x); return 0; }
Attempts:
2 left
💡 Hint
Check the size of long int on a 32-bit or 64-bit system and the literal value.
✗ Incorrect
The literal 2147483648 fits in a long int on 64-bit systems. The output prints the positive number 2147483648.
🔧 Debug
advanced2:00remaining
Why does this code print a negative number?
This code prints a negative number instead of the expected positive value. Why?
C
#include <stdio.h> int main() { unsigned int a = 4000000000U; int b = a; printf("%d\n", b); return 0; }
Attempts:
2 left
💡 Hint
Think about how large values in unsigned int convert to signed int.
✗ Incorrect
The value 4000000000 exceeds the max of signed int (usually 2147483647). Assigning it to int causes overflow and prints a negative number due to two's complement representation.
📝 Syntax
advanced2:00remaining
Which option causes a compilation error?
Which of the following C declarations will cause a compilation error?
Attempts:
2 left
💡 Hint
Check if 'unsigned signed' is a valid combination.
✗ Incorrect
'unsigned signed int' is invalid because 'unsigned' and 'signed' cannot be combined together for the same variable.
🧠 Conceptual
expert2:00remaining
Size difference between short, int, and long with modifiers
On a typical 64-bit system, which statement about sizes of these types is true?
Attempts:
2 left
💡 Hint
Check typical sizes: short is 2 bytes, int and long are usually 4 or 8 bytes on 64-bit.
✗ Incorrect
On a typical 64-bit system (such as Linux with LP64 data model), short int is 2 bytes, int is 4 bytes, long int is 8 bytes, so short int < int < long int.