c
  1. c-program-to-demonstrate-the-working-of-keyword-long

Program to Demonstrate the Working of Keyword long - C Programs

Example

#include <stdio.h>
int main()
{
   int i;
   long long num;
   printf("Enter an integer: ");
   scanf("%d", &i);
   num = i * i * i;
   printf("The cube of the number is: %lld", num);
   return 0;
}

Output

Enter an integer: 5
The cube of the number is: 125

Explanation

In the above program, we have declared two variables i and num. We have declared i as int and num as long long. The variable i can hold an integer value between -32768 to 32767. However, we want to store the cube of i in num which can hold a larger value than what i can hold. Therefore, we use long long to store the cube of i.

Use

The keyword long is generally used to declare variables that can store a larger value than what int can store. For example, long int can store values in the range of -2147483648 to 2147483647, while long long can store a value in the range of -9223372036854775808 to 9223372036854775807.

Summary

  • The keyword long is used to declare variables that can store a larger value than what int can store.
  • long int can store values in the range of -2147483648 to 2147483647, while long long can store a value in the range of -9223372036854775808 to 9223372036854775807.
Published on: