Loading lessons...
Integer Numbers and Modifiers
Integer Numbers and Modifiers
Integers are the whole numbers. C gives you several flavors via modifiers.
int
The plain int is signed and usually 4 bytes (about -2.1 billion to +2.1 billion):
int score = 1000000;
unsigned
unsigned gives up negatives to get a bigger positive maximum:
unsigned int big = 4000000000U;
short and long
short- smaller, often 2 bytes.long- larger, often 8 bytes on 64-bit machines.long long- even bigger.
short int small = 100;
long int huge = 1000000000;
long long int enormous = 9000000000000000000LL;
signed vs unsigned
signedcan hold negatives and positives (default for int).unsignedonly holds 0 and positives.
The %d family of specifiers
%d/%i- int%u- unsigned int%ld- long%lld- long long%hd- short
TL;DR
intis the common whole-number type (usually 4 bytes).unsignedswaps negatives for a bigger positive range.short,long,long longresize the integer.- Specifiers: %d, %u, %ld, %lld.