Variables declared with int data type can accommodate 32-Bit integer value i.e. 4BYTES.

  • The size varies from compiler to compiler i.e. in 32-bit TCC and BCC compiler the size of int is 2 BYTES. Whereas in GCC compiler it is of 4BYTES.
  • A few type modifiers such as short, long, signed and unsigned impact the Size and range of the integer data type.

Signed integer varies from -2,147,483,648 to +2,147,483,647 i.e. 31 bits for data and the most significant bit will represent sign (+/-).

Unsigned integer varies from 0 to 4,294,967,295. All the 32-bits represents data.

Declaring and defining an integer variable:

We need to mention the keyword int before the variable name to specify the variable is of type int and can store only integer value.

#include <stdio.h>

int main()
{
   /* <datatype> <variable 1>,<variable 2>,<variable 3>...... <variable N>; */
    int value;     /* Declaring an integer variable */
    value = 30;    /* Defining value to a variable */
    printf("The integer value is %d", value);    /* printing the value on to the screen */
    return 0;
}
  1. %d is the format specifier to represent the variable is of type int.
  2. 'value' is a variable name.

Initializing an integer variable:

Declaration + Definition = Initialization;

#include <stdio.h>

int main()
{
    int value = 30;    /* Declaring and defining (Initializing) the value at same time */
    printf("The value is  %d", value);
    return 0;
}

Binary representation:

The below binary representation will show, how the value 30 will be stored in memory.

  • The default type modifier of an integer variable is 'signed'.
  • The integer variable can hold only one integer value at a time.

Wrap-up Behaviour of integer:

If the assigned value is not in the range of the data type then the value will be wrapped up.

For example:

  • If we initialize the variable with the value2,147,483,648which is not in the range of integer, so it will be wrapped up to the opposite value in the range i.e-2,147,483,648. Similarly for 2,147,483,649will be wrapped up to-2,147,483,647.
  • For an unsigned integer,4,294,967,296 will be wrapped up to 0.