0
0
Cprogramming~20 mins

Type modifiers in C - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Type Modifier Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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;
}
A128
B-128
C0
D255
Attempts:
2 left
💡 Hint
Remember that signed char max is 127 and unsigned char max is 255. The addition promotes both to int.
Predict Output
intermediate
2: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;
}
A0
B-2147483648
C2147483648
DCompilation error
Attempts:
2 left
💡 Hint
Check the size of long int on a 32-bit or 64-bit system and the literal value.
🔧 Debug
advanced
2: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;
}
ABecause 4000000000 is too small for unsigned int.
BBecause unsigned int cannot hold values above 32767.
CBecause printf with %d expects unsigned int, but got int.
DBecause assigning unsigned int to int causes overflow and negative value due to two's complement.
Attempts:
2 left
💡 Hint
Think about how large values in unsigned int convert to signed int.
📝 Syntax
advanced
2:00remaining
Which option causes a compilation error?
Which of the following C declarations will cause a compilation error?
Along long int y;
Bunsigned signed int x;
Csigned int z;
Dunsigned int w;
Attempts:
2 left
💡 Hint
Check if 'unsigned signed' is a valid combination.
🧠 Conceptual
expert
2: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?
Ashort int < int < long int
Bshort int == int < long int
Cshort int == int == long int
Dshort int < int == long int
Attempts:
2 left
💡 Hint
Check typical sizes: short is 2 bytes, int and long are usually 4 or 8 bytes on 64-bit.