CodeBlanks Logo Icon CodeBlanks

Integer types

Learn int, short, long, long long and unsigned types.

Integer types

C has several integer types. The most common ones:

  • short: small integer (usually 2 bytes)
  • int: standard integer (usually 4 bytes)
  • long: large integer (usually 8 bytes)
  • unsigned: no sign; only zero and positive

The choice depends on how big a number you want to store. unsigned drops the negative side and doubles the positive side.

Type limits

Each integer type has minimum and maximum values it can store. The limits.h header defines these:

  • INT_MIN / INT_MAX: int bounds
  • LONG_MIN / LONG_MAX: long bounds

Exceeding the limit causes overflow and the result is undefined. Prefer long or long long when working with large numbers.

Practice Declare long and unsigned

Declare a long big = 1000000L; and an unsigned int count = 50;. Print big with printf using %ld.

Starter code

main.c
// declare long and unsigned int, print with printf

Sample solution

main.c
#include <stdio.h>

int main(void) {
    long big = 1000000L;
    unsigned int count = 50;
    printf("%ld", big);
    return 0;
}

Expected output

1000000

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 Which is an integer type?

  • double
  • int Correct answer
  • char
  • void

Explanation: int stores integer values.

2 Unsigned declaration

Question
unsigned ____ count = 100;
Answer
unsigned int count = 100;

Explanation: unsigned int is used for non-negative integers.

3 Match type and size

Term Meaning
int 4 bytes
short 2 bytes
long 8 bytes
char 1 byte

All lessons in Beginner