A type modifier in C changes the meaning or size of a basic data type, like int or char. Examples include signed, unsigned, short, and long.
Click to reveal answer
beginner
What does the unsigned modifier do?
The unsigned modifier tells the compiler the variable can only hold zero or positive values, removing the ability to store negative numbers.
Click to reveal answer
intermediate
How does long int differ from int?
long int usually uses more memory than int, allowing it to store larger numbers. The exact size depends on the system but long means 'longer' or 'bigger'.
Click to reveal answer
intermediate
Can you combine multiple type modifiers? Give an example.
Yes, you can combine them. For example, unsigned long int means a large integer that cannot be negative.
Click to reveal answer
intermediate
What is the difference between signed char and unsigned char?
signed char can hold negative and positive values, while unsigned char holds only non-negative values (including zero). Both store small integers but differ in range.
Click to reveal answer
Which type modifier allows only non-negative values?
Ashort
Bunsigned
Clong
Dsigned
✗ Incorrect
The unsigned modifier restricts values to zero and positive numbers only.
What does short int usually mean?
AA smaller integer type
BA larger integer type
CAn unsigned integer
DA floating-point number
✗ Incorrect
short int typically uses less memory than int, so it stores smaller numbers.
Which of these is a valid combination of type modifiers?
Along float
Bsigned unsigned int
Cshort double
Dunsigned long int
✗ Incorrect
unsigned long int is valid. signed unsigned int is contradictory, and long float or short double are invalid.
What is the default sign for int if no modifier is given?
Aunsigned
Blong
Csigned
Dshort
✗ Incorrect
By default, int is signed, meaning it can hold negative and positive values.
Which type modifier affects the size of the data type?
Along
Bunsigned
Csigned
Dconst
✗ Incorrect
long changes the size (usually larger), while unsigned and signed affect the sign, and const affects mutability.
Explain what type modifiers are in C and give examples.
Think about how you can change the size or sign of a number type.
You got /3 concepts.
Describe the difference between signed and unsigned types and why you might use each.
Consider when you need negative numbers or only positive numbers.
You got /3 concepts.
Practice
(1/5)
1. Which of the following type modifiers in C is used to store only non-negative values?
easy
A. short
B. signed
C. long
D. unsigned
Solution
Step 1: Understand the meaning of 'unsigned'
The 'unsigned' modifier means the variable can only hold zero or positive values, no negatives.
Step 2: Compare with other modifiers
'signed' allows negative and positive values, 'short' and 'long' change size but not sign.
Final Answer:
unsigned -> Option D
Quick Check:
unsigned = non-negative only [OK]
Hint: Unsigned means no negative numbers allowed [OK]
Common Mistakes:
Confusing 'signed' with 'unsigned'
Thinking 'short' affects sign
Assuming 'long' means unsigned
2. Which of the following is the correct way to declare a variable as a long unsigned integer in C?
easy
A. unsigned long int var;
B. int long unsigned var;
C. int unsigned long var;
D. unsigned int long var;
Solution
Step 1: Recall correct order of type modifiers
The standard order is 'unsigned long int' to declare a long unsigned integer.
Step 2: Check syntax correctness
unsigned long int var; follows the correct order and syntax; others mix order incorrectly.
Final Answer:
unsigned long int var; -> Option A
Quick Check:
unsigned long int = correct order [OK]
Hint: Use 'unsigned long int' order for clarity [OK]
Common Mistakes:
Mixing order of 'unsigned' and 'long'
Placing 'int' before 'unsigned'
Using invalid modifier order
3. What will be the output of the following C code?
unsigned short x = 65535;
unsigned short y = 1;
unsigned short z = x + y;
printf("%u", z);
medium
A. 0
B. 65536
C. 1
D. 65535
Solution
Step 1: Understand the range of unsigned short
Unsigned short typically stores values from 0 to 65535 (16-bit).
Step 2: Calculate the sum and check overflow
65535 + 1 = 65536, which exceeds max value, so it wraps around to 0.
Final Answer:
0 -> Option A
Quick Check:
Unsigned short overflow wraps to 0 [OK]
Hint: Unsigned short max is 65535; adding 1 wraps to 0 [OK]
Common Mistakes:
Expecting 65536 as output (overflow ignored)
Confusing signed and unsigned overflow
Using wrong printf format specifier
4. Identify the error in this C declaration:
unsigned signed int num;
medium
A. Missing variable name
B. Should use 'long' instead of 'signed'
C. Cannot combine 'unsigned' and 'signed' modifiers
D. No error, valid declaration
Solution
Step 1: Understand modifier compatibility
'unsigned' and 'signed' are opposite modifiers and cannot be combined together.
Step 2: Check declaration validity
Combining both causes a syntax error; variable name is present, so no missing name error.
Final Answer:
Cannot combine 'unsigned' and 'signed' modifiers -> Option C
Quick Check:
unsigned + signed = invalid [OK]
Hint: Don't mix 'unsigned' and 'signed' together [OK]
Common Mistakes:
Thinking both can be combined
Ignoring opposite meanings
Assuming 'signed' is default and can be added
5. You want to store a large positive number that fits in 64 bits but never needs to be negative. Which type modifier combination is best in C?
hard
A. short unsigned int
B. unsigned long long int
C. long int
D. signed long long int
Solution
Step 1: Identify size and sign requirements
64 bits means 'long long' type; only positive means 'unsigned'.
Step 2: Match modifiers to requirements
'unsigned long long int' fits large positive numbers without negatives.
Final Answer:
unsigned long long int -> Option B
Quick Check:
64-bit positive number = unsigned long long int [OK]
Hint: Use 'unsigned long long int' for large positive 64-bit numbers [OK]
Common Mistakes:
Choosing signed type when negatives not needed
Using 'short' which is too small
Ignoring 'unsigned' for positive-only data
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.