Type Modifiers: signed, unsigned, short, long in C
Modifiers tune integer range without new types. signed (the default) splits bits across negative and positive; unsigned spends all bits on non-negative values, doubling the maximum β ideal for sizes and counts. short shrinks (at least 16 bits); long and long long grow (long long is at least 64 bits).
The classic trap is mixing signed and unsigned: the signed value converts to unsigned, turning -1 into 4294967295 and breaking loop conditions with zero warnings by default. Compile with -Wsign-compare and use size_t consistently for sizes.
signed vs unsigned
int spans roughly β2B..+2B; unsigned int spans 0..~4B β same 32 bits, different reading of the top bit.
short and long
short saves space (β₯16 bits); long and long long extend upward β long long guarantees β₯64 bits.
Where unsigned shines
Sizes, counts, bit work β anything semantically non-negative, like strlen()'s size_t return.
The mixed-sign trap
In `i < strlen(s)` with int i, i converts to unsigned β a negative i becomes huge and the test misbehaves. Compare size_t with size_t.
#include <stdio.h>Β int main(void) { unsigned int u = 5; long long big = 9000000000LL; printf("%u, %lld\n", u, big); printf("%zu vs %zu\n", sizeof(int), sizeof(long long)); return 0;}Recommended resourcesAffiliate links Β· may earn us a commission
Recommended for learners
Practice what you learned
Re-implement each visualized algorithm in C yourself β building beats watching.