C Long

Last Updated : 4 Apr, 2026

In C, long is a data type modifier used to increase the storage capacity and numerical range of standard types. It ensures your variables can handle larger values than the base types might allow on specific architectures.

  • Purpose: Expands the bit-width of int and double to prevent overflow when working with large datasets.
  • Capacity: On a 16-bit system, a standard int is limited to 32,767, whereas long int extends this to over 2 billion.
  • Flexibility: It can be applied as long int, long long int, or long double, depending on the precision required.
  • Memory: While it increases range, it also consumes more memory, for example, a long long typically occupies 8 bytes compared to the standard 4-byte int.

How to use long modifier?

We can apply the long modifier to the allowed data types just by adding it as a prefix in the normal variable declaration. For example:

int var; // normal declaration
long int var; // long int variable declaration

One thing to note here is that we cannot use the long modifier with any data type of our choice. In C, we can only use long with 3 datatypes which are as follows:

  1. long int
  2. long long int
  3. long double

Note: The size of the long int and other variables varies depending upon the compiler and system architecture.

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.

  • The size of the long int is typically 4 bytes.
  • It can store integer values that range from -2,147,483,648 to 2,147,483,647.
  • The format specifier for long int is %ld.
  • The long int literals can be represented by a numeric value followed by "L" or "l" as the suffix.

Syntax of long int

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.

  • The size of the long long int is typically 8 bytes.
  • It can represent integer values from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807.
  • The format specifier for the long long data type is %lld.
  • The long int literals can be represented by a numeric value followed by "LL" or "ll" as the suffix.

Syntax of long long int

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. 

  • The size of a long double is typically 16 bytes.
  • It provides more accuracy, precision and a larger range than the standard double data type.
  • The format specifier for long double is %Lf.

Syntax of long double

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

When to Use long in C?

  • Use it when the data you are handling is expected to exceed the maximum limit of standard int or double.
  • Use long long if you specifically need a 64-bit integer, as the size of long can vary between Windows and Linux.
  • Use long double in scientific or financial applications where decimal accuracy is critical.
  • Avoid using long modifiers by default - they consume more RAM and can slightly slow down processing on some architectures. Only use them when the range is necessary.
Comment