Skip to content
StudyFame

Type Modifiers in C

Sometimes int is too small, and sometimes you never need negative numbers. C lets you adjust a basic type with four words: signed, unsigned, short and long.

These are called type modifiers. In this lesson you will learn what each one does to the size and range of a type.

What You Will Learn

  • What type modifiers are.
  • The difference between signed and unsigned.
  • What short, long and long long do.
  • The size and range table of integer types.
  • What happens when a value goes out of range (overflow).

Type Modifiers in C Explained

Exam definition: Type modifiers are keywords used with basic data types to change their size or range. C has four modifiers: signed, unsigned, short and long.

ModifierWhat it doesUsed with
signedAllows positive and negative values (default for int)char, int
unsignedOnly zero and positive values, so the positive range doubleschar, int
shortSmaller size (usually 2 bytes)int
longBigger sizeint, double

Memory trick: signed = has a sign (+ or −). unsigned = no sign, so no negatives. short = small box, long = big box.

Size and range table (usual on 64-bit systems)

TypeSizeRangeFormat
signed char1 byte−128 to 127%c / %d
unsigned char1 byte0 to 255%c / %u
short2 bytes−32,768 to 32,767%hd
unsigned short2 bytes0 to 65,535%hu
int4 bytes−2,147,483,648 to 2,147,483,647%d
unsigned int4 bytes0 to 4,294,967,295%u
long8 bytes (4 on Windows)Same as long long (or int on Windows)%ld
long long8 bytesabout ±9.22 × 1018%lld
long double8, 12 or 16 bytesMore precision than double%Lf

Why does unsigned double the positive range?

  • A 1-byte char can hold 256 different values.
  • signed: half for negatives, half for zero and positives → −128 to 127.
  • unsigned: all 256 values for zero and positives → 0 to 255.

Syntax of Type Modifiers

unsigned int  students = 4000000000u;
short int     year     = 2026;        /* "int" can be left out: short year */
long long     stars    = 9000000000LL;
unsigned char pixel    = 255;

short int and short mean the same. unsigned alone means unsigned int. The suffixes u and LL mark a number as unsigned or long long.

Example 1: Print the Range of int Using limits.h

The header limits.h has ready-made names for the smallest and largest values of each type.

#include <stdio.h>
#include <limits.h>

int main(void)
{
    printf("int minimum     : %d\n", INT_MIN);
    printf("int maximum     : %d\n", INT_MAX);
    printf("unsigned int max: %u\n", UINT_MAX);
    printf("short maximum   : %d\n", SHRT_MAX);
    return 0;
}

Output

int minimum     : -2147483648
int maximum     : 2147483647
unsigned int max: 4294967295
short maximum   : 32767

Code Explanation

  1. #include <limits.h>: brings in the limit names.
  2. INT_MIN, INT_MAX: smallest and largest int.
  3. UINT_MAX: largest unsigned int. It is printed with %u (unsigned).
  4. SHRT_MAX: largest short.

How Range Works (Overflow)

  • Each type has a fixed number of bits, so it can only hold values in its range.
  • For unsigned types, going past the maximum wraps around to 0, like a car's odometer going from 99999 to 00000.
  • For signed types, going past the maximum is undefined behaviour: the result is unpredictable. Never rely on it.
  • So choose a type big enough for your data. Population of India? Use long long, not int.

Example 2: Unsigned Overflow Wraps Around

#include <stdio.h>

int main(void)
{
    unsigned char level = 255;   /* the maximum for unsigned char */

    printf("Before: %u\n", level);
    level = level + 1;           /* goes past the maximum */
    printf("After : %u\n", level);

    return 0;
}

Output

Before: 255
After : 0

255 + 1 does not fit in 1 byte, so it wraps around to 0. Bugs like this happen when the type is too small.

Important Points to Remember

  • 4 type modifiers: signed, unsigned, short, long.
  • int is signed by default.
  • unsigned = no negative values, double the positive range.
  • short is usually 2 bytes; long long is 8 bytes.
  • Unsigned overflow wraps to 0; signed overflow is undefined.

Common Mistakes Beginners Make

MistakeWhat happensFix
Storing −5 in an unsigned intBecomes a huge positive number (4294967291)Use a signed type for values that can be negative
Printing long long with %dWrong valueUse %lld
Using int for very big valuesOverflow, wrong resultsUse long long
Assuming long is 8 bytes everywhereIt is 4 bytes on WindowsUse long long for 8 bytes

Type Modifiers Practice Questions

  1. Name the four type modifiers in C.
  2. What is the difference between signed and unsigned?
  3. What is the range of unsigned char?
  4. Which format specifier prints long long?
  5. What happens when an unsigned char with value 255 is increased by 1?
Show answers
  1. signed, unsigned, short, long.
  2. signed stores positive and negative values; unsigned stores only zero and positive values, with double the positive range.
  3. 0 to 255.
  4. %lld
  5. It wraps around to 0.

Coding Exercise

Write a program that stores the distance from the Earth to the Sun in kilometres (149600000) in a suitable type and the number of seconds in 100 years (100 × 365 × 24 × 60 × 60) in a long long. Print both.

Show solution
#include <stdio.h>

int main(void)
{
    long long distance_km = 149600000LL;
    long long seconds = 100LL * 365 * 24 * 60 * 60;

    printf("Earth to Sun: %lld km\n", distance_km);
    printf("Seconds in 100 years: %lld\n", seconds);
    return 0;
}
Earth to Sun: 149600000 km
Seconds in 100 years: 3153600000

3,153,600,000 is bigger than INT_MAX, so int would overflow. Writing 100LL makes the whole calculation use long long.

Quick Quiz: Type Modifiers in C (MCQ)

  1. Which is NOT a type modifier?

    A) short   B) long   C) static   D) unsigned

  2. The range of unsigned char is:

    A) −128 to 127   B) 0 to 255   C) 0 to 127   D) −255 to 255

  3. The usual size of short is:

    A) 1 byte   B) 2 bytes   C) 4 bytes   D) 8 bytes

  4. Which format specifier prints an unsigned int?

    A) %d   B) %u   C) %ld   D) %f

  5. int is ______ by default.

    A) unsigned   B) signed   C) short   D) long

Show answers
  1. C: static is a storage class, not a type modifier.
  2. B: 0 to 255.
  3. B: 2 bytes.
  4. B: %u.
  5. B: signed.

Quick Revision for Exams and Interviews

Read this before your exam. The highlighted words are the answer.

Must-remember facts

Modifierssigned, unsigned, short, long
signed char−128 to 127
unsigned char0 to 255
short2 bytes, −32,768 to 32,767
int4 bytes, about ±2.1 billion
unsigned int max4,294,967,295
long long8 bytes, %lld
Limits headerlimits.h (INT_MAX, INT_MIN)

Frequently asked questions

What is the difference between signed and unsigned int?
signed holds negative and positive values; unsigned holds only positive values with double the positive range.
What happens on unsigned overflow?
The value wraps around to 0.
What happens on signed overflow?
It is undefined behaviour: the result cannot be predicted.
Is long always 8 bytes?
No. It is 8 bytes on 64-bit Linux and macOS but 4 bytes on Windows. long long is always at least 8 bytes.

Remember

  • signed = has a sign; unsigned = no negatives.
  • Formats: %u unsigned, %hd short, %lld long long.

Next Topic

Next lesson: Constants and Literals in C. You will learn how to create values that can never change.