C Program to Demonstrate the Working of Keyword long

Introduction

The long keyword is also used as a data type in programming languages. Same as other data types, its size also varies from compiler to compiler i.e., the 64-bit compiler would give a size of long as 8 bytes whereas 32-bit compiler gives size as 4 bytes.

Note: The ‘long’ keyword is never used with ‘char’ and ‘float’ data types.

Let’s understand its functioning with the help of a program.

Program

#include<stdio.h>

int main()

{

int x;

long y;

double z;

long int u;

long long v;

long double w;




printf("Size of int variable: %d bytes\n",sizeof(x));

printf("Size of long variable: %d bytes\n",sizeof(y));

printf("Size of double variable: %d bytes\n\n",sizeof(z));

printf("Size of long int variable: %d bytes\n",sizeof(u));

printf("Size of long long variable: %d bytes\n",sizeof(v));

printf("Size of long double variable: %d bytes\n",sizeof(w));

return 0;

}

 

Output

Explanation

In the above program, firstly we access the size of int, long, and double data types by writing the statements

printf(“Size of int variable: %d bytes\n”,sizeof(a));

printf(“Size of long: %d bytes\n”,sizeof(b));

printf(“Size of double: %d bytes\n\n”,sizeof(c));

and that give 4, 4, 8 respectively as output. Thus, size of long keyword is 4.

printf(“Size of long int: %d bytes\n”,sizeof(d));

While using ‘long’ with other data types we came to know that ‘long int’ is equivalent to ‘long’ and ‘int’ since all three have the same size i.e., 4 bytes.

printf(“Size of long long: %d bytes\n”,sizeof(e)); this statement gives size of ‘long long’ as 8.

printf(“Size of long double: %d bytes\n”,sizeof(f)); this statement gives size of ‘long double’ as 8.

This means that size of ‘long long’ and ‘long double’ is greater than the other data types.

 

Author

  • Barry Allen

    A Full Stack Developer with 10+ years of experience in different domain including SAP, Blockchain, AI and Web Development.

    View all posts

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.