Integer Data Type with Long Modifier
In this tutorial, we will learn about the long modifier and its significance when used with integer data types.
In this tutorial, we will learn about the long modifier and its significance when used with integer data types.
A modifier is used to change or modify the type of something. There are different types of modifiers that can be used with integers:
These modifiers can be added before an integer type to change its default size and range.
The detailed explanation of short modifier is available in this article.
The long modifier is used to increase the size of an integer type from its default size.
Syntax:
long int variable_name;
Or
int long variable_name;
Let’s consider the following program:
#include <stdio.h>
int main()
{
long int var = -40845874;
printf("The integer value stored in variable var is %ld and ", var);
printf("the size of long integer in my machine is %d bytes", sizeof(var));
}
Output:
Please note that the size of a long int
on my machine is 4 bytes, but it may be 8 bytes on your machine. The size depends on the compiler. However, keep in mind the following fact:
Fact
The size of a long int may not be greater than the size of an int on some machines, but one thing is certain: the size of an int can never be greater than the size of a long int.
You can calculate the range of a long int
using the following formula:
where n represents the number of bits.
Therefore, a long int with 4 bytes (32 bits) has the following range:
Syntax:
unsigned long int variable_name;
Or
unsigned int long variable_name;
Let’s consider the following program:
#include <stdio.h>
int main()
{
unsigned long int var = 907243902;
printf("The integer value stored in variable var is %lu and ", var);
printf("the size of unsigned long integer in my machine is %d bytes", sizeof(var));
}
Output:
The range of unsigned long int
type of 4 bytes (32 bits) is
Leave a comment