In order of size, starting with the smallest, the integer types are char, short,int, long and long long. The smaller types have the advantage of taking up less memory, the larger types incur a performance penalty. Variables of type int store the largest possible integer which does not incur this performance penalty. For this reason, int variables can be different depending what type of computer you are using.

On “32-bit” machines the int data type takes up 4 bytes (232). The short is usually smaller, the long can be larger or the same size as an int and finally the long long is for handling very large numbers.long long is an integer type which is at least 64-bit    (8 byte )wide.

We can  easily get the size of these datatype by using  sizeof(data_type_name) in c program.

An Unsigned int can hold zero and positive numbers but a signed  int holds negative, zero or positive numbers.

One of the good example I came across is :

int main() {
    unsigned long long int num = 285212672; //FYI: fits in 29 bits
    int normalInt = 5;
    printf("My number is %d bytes wide and its value is %ul. A normal number is %d.\n", sizeof(num), num, normalInt);
    return 0;

o/p :
My number is 8 bytes wide and its value is 285212672l. A normal number is 0.

Second one is :

#include <stdio.h>;

int main()
    int  num1 = 1000000000;
    long num2 = 1000000000;
    long long num3;
    num3 = 100000000000LL;
    long long num4 = ~0;

    printf("%u %u %u", sizeof(num1), sizeof(num2), sizeof(num3));
    printf("%d %ld %lld %llu", num1, num2, num3, num4);
    return 0;

in second example :The suffix LL makes the literal into type long long. In Cwe have to conclude this from the type on the left, the type is a property of the literal itself.

On major 32-bit platforms:
  • int is 32 bits
  • long is 32 bits as well
  • long long is 64 bits

On major 64-bit platforms:

  • int is 32 bits
  • long is either 32 or 64 bits
  • long long is 64 bits as well

Going by the standard:

  • int must be at least 16 bits
  • long must be at least 32 bits
  • long long must be at least 64 bits

Hope you learnt something special..keep coding 🙂

(source : ,