C Integer Data Types

C integer data represents the same as all the mathematical real number to be calculated in the programs. The integer data type is a common feature of almost all the modern programming languages. But the way of representation or declaration of integer numbers may vary language to language.

In this tutorial, we will learn the various methods of integer numbers declarations, calculations and their implementations in the C programming language.

So first of all, we have to keep the integer numbers in the memory address for working with those numbers later in the program. And the way of keeping those numbers in a memory address is declaring the number using a variable. So far we have learned about the variable declaration in a previous lesson.

As C is a statically typed language we have to mention the data type before declaring a variable for integer types. In C, int is the keyword for declaring integer data-container in the memory address.  And the following syntax consists of declaring integers in C.

Example (main.c):

#include <stdio.h>
int main() {
    int a; //declaring single integer without initialization
    int b, c, d, sum; // multiple integers without initialization
    int e=10; //single integer with initialization
    int f=12, g=19; //multiple integers with initialization

    /* initializing value of uninitialized variable */
    a = 14;
    b = 18;
    c = 25;
    d = 36;

    /* re-initializing value of initialized variable
       or changing value of a existing integer value */
    e = 95;

    /* Printing values of integer variables */
    printf("%d \n", a); // printing single variable
    printf("%d %d %d \n", c, d, e); // printing multiple variable

    /* simple arithmetic operations of integers */
    sum = a + b; // sum must have to declare before assaiging values
    printf("%d", sum); // displaying calculated value of sum

    return 0;

In the above single program, we tried to show all the basic syntax of declaring integer data type or integer variables. Now if you compile and run the code, you should get the following;


25 36 95

In the above output, notice that the third line 32 was the sum variable a and b. We will work with integer numbers with advanced calculations in the later lessons.

C Integer modifiers, size and value ranges

Depending on value ranges and memory allocation size integer type can be modified in many ways in C. Integer data can be stored in the memory address with signed and unsigned format. And both of them have some modifiers for increasing or decreasing memory size like long, short, long long, etc. The following table consists of C integer modifiers:

Data TypeSignedUnsigned
Intintorsigned intunsigned int
short intorsigned short intunsigned short int
long intorsigned long intunsigned long int
long long intorsigned long long intunsigned long long int

In the above table notice that int and signed int represented as same, and for the remainings are also the same. It is because of all the integer data types are signed by default unless they are declared with the unsigned keyword. So while declaring a signed variable it is not necessary to define the signed keyword.

Each of every single modified integer data types in the above table has a different storage size and value range. For example, short int takes 2 bytes of data from the memory when it is declared. See more at the following table:

Data TypesMemory sizeMin. ValueMax. Value
int2 or 4 bytes-32,768 or -2,147,483,64832,767 or 2,147,483,647
unsigned int2 or 4 bytes065,535 or 2,147,483,647
short int2 bytes-32,76832,767
unsigned short int2 bytes065,535
long int4 bytes-2,147,483,6482,147,483,647
unsigned long int4 bytes04,294,967,295
long long int8 bytes-9,223,372,036, 854,775,8089,223,372,036, 854,775,807
unsigned long long8 bytes018,446,744,073, 709,551,615

Using the above data types you can access the corresponding memory size and value ranges in your program.

Placeholder for modifiers

We have learned how to print the value of a variable in the printf function using %d placeholder or format specifier for corresponding variables. But for integer type, all the time the placeholder is not the same. It varies for the modified data types like short int, long int, etc. See the following table for more:

Data TypesPlaceholder
short int%hi
unsigned short int%hu
long int%l or %ld or %li
unsigned long int%lu
long long int%lli, %lld
unsigned long long int%llu

Now we will see an example program for testing the above format specifiers are working or not. See the example below.


#include <stdio.h>
int main() {
    short int a = 35000, b = 3000; //declaring short int type
    long int c = 345; //declaring long int type

    /* short int has the value range of -32,768 to 23767.
    if you declare a higher value in short int than max value
    the execution will be wrong. see output for the below line */
    printf("Out of range: %hi \nIn the range: %hi \n", a, b);

    printf("Long value: %ld \n", c); //you can also use %l or %li

    return 0;


Out of range: -30536
In the range: 3000
Long value: 345

Notice that the value of out of range is not showing correctly. It is because of the range limitation of the short int data type. Now you should practice the remaining types randomly on your computer. Happy coding.

« Previous Next »