Demonstrate the Working of Keyword long in C

Exercise:

Write a C program to demonstrate the working of key word long.

Click Here to View the Solution!
#include <stdio.h>
int main() {
    int a;
    long b;
    long long c;  // equivalent to long long int c;
    double e;
    long double f;
    printf("Size of int data type = %zu bytes \n", sizeof(a));
    printf("Size of long int data type = %zu bytes\n", sizeof(b));
    printf("Size of long long int data type = %zu bytes\n", sizeof(c));
    printf("Size of double data type = %zu bytes\n", sizeof(e));
    printf("Size of long double data type = %zu bytes\n", sizeof(f));
    return 0;
}
Click Here to View the Output!
Size of int data type = 4 bytes
Size of long int data type = 4 bytes
Size of long long int data type = 8 bytes
Size of double data type = 8 bytes
Size of long double data type = 16 bytes
Click Here to View the Explanation!
  • This program is used to determine the difference between the working of long keyword in comparison to other simple data types.
  • In the main method, variables of different data types are initialized.
  • The printf() functions determine the sizes of the data types int, long, long long, double and long double using the sizeof() operator.
  • The sizes specify that the long int, long long int and long double are greater in size than their corresponding simple data types.
  • The size_t which is an unsigned integral datatype is returned by the sizeof() operator. It displays the size of an object using a format specifier %zu.
  • The long keyword limited to only int and double data types.
  • The program exits using the return 0 statement.