Long Data Type in C
Long Keyword
On this page we will discuss about Long Data Type which is used in C. The Long data type is a data type that represents a signed integer that is typically at least 32 bits long.
More About Long Keyword in C Language
In C Programming, long data type is used to store larger integer values that are too large to be stored in a int data type.
The long data types with their storage size, range and format specifier are given in the table below:
Data Type | Storage size | Range | Format Specifier |
---|---|---|---|
long | 4 bytes | -2,147,483,648 to +2,147,483,647 | %ld |
long long | 8 bytes | -9,223,372,036,854,775,808 to +9,223,372,036,854,775,807 | %lld |
long double | 10 bytes | 3.4E-4932 to 1.1E+4932 | %lf |
The range of values that can be stored in a long variable depends on the implementation of the C compiler and the specific system it is being run on.
Declaration of Long Data type variable
long p; long long q; long double r;
Initialization of Long Data type variable
A long data type variable can be initialized in two ways as follows:
1. By assigning value to a variable using assignment operator.
p = 1234567890; q = 123456789012345678; r = 5.67e+2;
2. By assigning value to a variable during declaration only using an assignment operator.
long p = 1234567890; long long q = 123456789012345678; long double r = 5.67e+2;
Program to print Long Data Types
Example 1:
#include <stdio.h> int main() { // Declare a long variable and initialize it with a value long num = 1234567890; // Print the value of the long variable printf("The value of num is: %ld\n", num); // Add two long variables and store the result in another long variable long result = num + 1234567890; printf("The result is: %ld\n", result); return 0; }
Output:
The value of num is: 1234567890 The result is: 2469135780
Example 2:
#include <stdio.h> int main() { // Declare a long double variable and initialize it with a value long double num = 123.456789012345678; // Print the value of the long double variable printf("The value of num is: %Lf\n", num); // Add two long double variables and store the result in another long double variable long double result = num + 123.456789012345678; printf("The result is: %Lf\n", result); return 0; }
Output:
The value of num is: 123.456789 The result is: 246.913578
Prime Course Trailer
Related Banners
Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription
Get over 200+ course One Subscription
Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others
Login/Signup to comment