# What Is the Size and Range of Data Type Long?

//

Larry Thompson

What Is the Size and Range of Data Type Long?

The long data type is used to store large whole numbers in programming languages such as Java, C++, and C#. It is capable of holding values that are beyond the capacity of the int data type. In this article, we will explore the size and range of the long data type.

## Size of the long Data Type

The long data type typically occupies 8 bytes or 64 bits of memory. This allows it to represent integers in the range of -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807. The size of a long may vary depending on the programming language or system architecture.

## Range of Values for long Data Type

The range of values that can be stored in a long variable is determined by the number of bits it occupies. With 64 bits available for storage, a signed long can represent values from -9 quintillion to 9 quintillion.

Here is an example to illustrate the range:

• Largest Value:
• The largest positive value that a long variable can hold is 9,223,372,036,854,775,807.

• Smallest Value:
• The smallest negative value that a long variable can hold is -9,223,372,036,
854,
775,
808.

• Zeros:
• A long variable can also hold zero (0) as a valid value.

## Usage and Considerations

The long data type is commonly used in scenarios where extremely large values need to be stored, such as timestamp calculations, representing file sizes, or dealing with astronomical measurements. It provides developers with a wider range of values compared to the int data type.

It is important to note that using the long data type comes with a tradeoff in terms of memory consumption. Since it requires 8 bytes of memory, using long variables extensively can lead to increased memory usage.

When assigning values to a long, it is recommended to use the suffix “L” or “l” at the end of the number literal. For example:

```   long largeNumber = 1234567890L;
long anotherLargeNumber = -9876543210l;
```

## In Conclusion

The long data type allows programmers to store and manipulate extremely large whole numbers. It offers a wider range of values compared to the int data type, but at the expense of increased memory usage. Understanding the size and range of the long data type is crucial when working with large numerical values in programming languages.

Privacy Policy