C Long (original) (raw)

Last Updated : 15 Jun, 2026

The long keyword in C is a data type modifier used to increase the storage capacity and range of numeric data types. It helps store larger values and reduces the risk of overflow.

**Example: A standard int may store values up to around 32,767 on some systems, while a long int can store values exceeding 2 billion.

Using the long Modifier in C

The long modifier is added before a valid data type during variable declaration to increase its storage capacity and numerical range.

**Example:

int var; // Normal declaration
long int var; // Long integer declaration

long int is used when a larger range is required than a standard int can provide.

1. long int

When long is applied to an integer it creates a long int, which increases the range of values that int can store. The long int is used when the range of values exceeds the int data type.

Syntax

long int var1; or, long var2;

Here, both var1 and var2 are of the same datatype and carry the same size.

**Example: The following code compares the storage capacity and memory size of a standard int versus a long int.

C `

#include <stdio.h>

int main() { // Max 32-bit int int a = 2147483647;

// Exceeds standard 32-bit int
long b = 3000000000L;    

printf("Long Value: %ld\n", b);
printf("Sizes: int = %zu, long = %zu bytes\n",
        sizeof(a), sizeof(b));
return 0;

}

`

Output

Long Value: 3000000000 Sizes: int = 4, long = 8 bytes

2. long long int

We can even apply the long modifier to long int to further increase the size of the data type. The long long int is often used when the range of values exceeds the long data type.

Syntax

long long int var; or, long long var;

**Example: This example demonstrates how to declare long long variables and check their memory footprint using sizeof.

C `

#include <stdio.h>

int main() { long long var = 9223372036854775807LL; printf("Large Value: %lld\n", var); printf("Size of long long: %zu bytes\n", sizeof(var)); return 0; }

`

Output

Large Value: 9223372036854775807 Size of long long: 8 bytes

3. long double

We can use a long modifier with double datatype to create a long double variable. Long double is used to store significantly large decimal numbers which surpass the range of double.

Syntax

long double var;

**Example: In below example, we initialize a long double to observe its increased precision and size.

C `

#include <stdio.h>

int main() { long double high_prec = 3.141592653589793238L; printf("Long Double: %Lf\n", high_prec); printf("Size: %zu bytes\n", sizeof(high_prec)); return 0; }

`

Output

Long Double: 3.141593 Size: 16 bytes

Use Cases of long in C

The long modifier should be used when the range or precision provided by standard data types is not sufficient for your application.