‘long’ Type Modifier in C

The long data type modifier is used to increase the size of a int or double data type by two times that also increases the range of these data types. For example, if int take 4 bytes of space it will take 8 bytes of space after using long with int.

Data Types with Long

The long can be used with following data types as:

  • long int
  • long long int
  • long double

Example

In the below code, we have declared the variables of integer and double type with and without using long modifier and then printed the size of each variables. In the output we can see that the size of long data type become double.

C




// C Program to illustrate size difference between int,
// long int, double and long double
#include <stdio.h>
  
int main()
{
    // defining variables with long
    int num;
    long int long_num;
    long long int long_long_num;
  
    double dub_num;
    long double long_dub_num;
  
    printf("Size of num: %d", sizeof(num));
    printf("\nSize of long_num: %d", sizeof(long_num));
    printf("\nSize of long_long_num: %d",
           sizeof(long_long_num));
    printf("\nSize of dub_num: %d", sizeof(dub_num));
    printf("\nSize of long_dub_num: %d",
           sizeof(long_dub_num));
  
    return 0;
}


Output

Size of num: 4
Size of long_num: 8
Size of long_long_num: 8
Size of dub_num: 8
Size of long_dub_num: 16

To know more, refer to the article – Long in C

Data Type Modifiers in C

In C, data type modifiers are used to modify the length or size of data that various data types hold such as int, char, and double as per the requirements. By using these data type modifiers we can precisely utilize the computer memory.

Primary Uses of Data Type Modifiers

  • To modify the size of the data type.
  • To modify the sign of the data type.

Similar Reads

Types of Modifiers

In C, we have 4 data type modifiers that are used to modify data types. They are used as prefixed to the basic data types. For example, unsigned int....

‘short’ Type Modifier in C

The short modifier works with integer data type. It decreases the size of the int to 2 bytes along with the range that decreases to -32,768 to 32,767....

‘long’ Type Modifier in C

...

‘unsigned’ Type Modifier in C

The long data type modifier is used to increase the size of a int or double data type by two times that also increases the range of these data types. For example, if int take 4 bytes of space it will take 8 bytes of space after using long with int....

‘signed’ Type Modifier in C

...