











Working of long Keyword in C Language
Long Keyword in C
On this page we will discuss about long keyword in C language. Long keyword is used to declare the long data type in C which is used store large integer values.So this page we will discuss their storage size, range and some examples related to long data type.


Working of Long Keyword in C
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.
Initialization of Long Data type variable
long a = 1234567890; long long b = 123456789012345678; long double r = 5.67e+2;
Example 1:
#include <stdio.h> int main () { int l; long m; long long n; double o; long double p; printf (" The size of int = %ld bytes \n", sizeof (l)); printf (" The size of long = %ld bytes\n", sizeof (m)); printf (" The size of long long = %ld bytes\n", sizeof (n)); printf (" The size of double = %ld bytes\n", sizeof (o)); printf (" The size of long double = %ld bytes\n\n", sizeof (p)); return 0; }
Output:
The size of int = 4 bytes The size of long = 8 bytes The size of long long = 8 bytes The size of double = 8 bytes The size of long double = 16 bytes
Example 2:
#include <stdio.h> int main () { long double p = 123.456789012345678; printf ("The value of p is: %Lf\n", p); long double res = p + 123.456789012345678; printf ("The result is: %Lf\n", res); return 0; }
Output:
The value of p 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