Learn C
#include "variablesdatatypes/type_modifiers.h"

Type Modifiers: signed, unsigned, short, long in C

#concept

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.

#how it works
1

signed vs unsigned

int spans roughly βˆ’2B..+2B; unsigned int spans 0..~4B β€” same 32 bits, different reading of the top bit.

2

short and long

short saves space (β‰₯16 bits); long and long long extend upward β€” long long guarantees β‰₯64 bits.

3

Where unsigned shines

Sizes, counts, bit work β€” anything semantically non-negative, like strlen()'s size_t return.

4

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.

#example
#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;
}
Output
5, 9000000000
4 vs 8
1The LL suffix makes the 9-billion literal long long; %u and %lld match the unsigned and long-long types.
2sizeof reports compile-time byte sizes β€” %zu is the correct specifier for size_t results.
3Both lines print as expected because every value fits its type and every specifier matches.
#use cases
Looping with size_t over strlen/buffer sizes to avoid sign warnings
Storing 64-bit timestamps and IDs that overflow 32-bit int
Enabling -Wsign-compare so mixed comparisons warn instead of misbehaving
Matching printf specifiers (%u, %lld, %zu) exactly to argument types

Recommended resourcesAffiliate links Β· may earn us a commission

Recommended for learners

Structured coding coursesVideo courses that pair well with visual practice β€” pick one language and go deep.Browse courses Pro code editor & AI assistantWrite, debug and explain code faster while you practice the patterns here.Try it free Classic DSA interview booksThe reference books interviewers themselves learned from β€” great next to the visualizers.See the books

Practice what you learned

Re-implement each visualized algorithm in C yourself β€” building beats watching.