C Program to Demonstrate the Working of Keyword long
Example: Program to Demonstrate the Working of long
#include <stdio.h>
int main()
{
int a;
long b;
long long c;
double e;
long double f;
printf("Size of int = %ld bytes \n", sizeof(a));
printf("Size of long = %ld bytes\n", sizeof(b));
printf("Size of long long = %ld bytes\n", sizeof(c));
printf("Size of double = %ld bytes\n", sizeof(e));
printf("Size of long double = %ld bytes\n", sizeof(f));
return 0;
}
Output
Size of int = 4 bytes Size of long = 8 bytes Size of long long = 8 bytes Size of double = 8 bytes Size of long double = 16 bytes
In this program, the sizeof
the operator is used to find the size of int
, long
, long long
, double
and long double
.
The long keyword cannot be used with float
and char
type variables.
program in C that demonstrates the use of the “long” keyword:
#include <stdio.h>
int main() {
int num1 = 10;
long num2 = 1000000000;
printf("Size of int: %d bytes\n", sizeof(num1));
printf("Size of long: %d bytes\n", sizeof(num2));
printf("Value of num1: %d\n", num1);
printf("Value of num2: %ld\n", num2);
return 0;
}
In this program, we have declared two variables: “num1” and “num2”. “num1” is an integer variable and “num2” is a long integer variable.
We then use the “sizeof” operator to print out the size of the integer and long integer data types. The output of this program would be:
Size of int: 4 bytes
Size of long: 8 bytes
Value of num1: 10
Value of num2: 1000000000
As we can see, the “long” keyword is used to declare a variable that can store larger integer values than the “int” data type. In this case, the “long” integer can store a value of up to 2^63-1, whereas the “int” data type can only store up to 2^31-1.