C Program To Demonstrate the Working of Keyword long

In this program, you will get to know how to demonstrate the working of long keyword in C Programming language.

C Program To Demonstrate the Working of Keyword long

The long is a size modifier keyword used to increase the size of a variable during declaration.

So, Without further ado, let’s get to know about the working of long keyword.

C Program To Demonstrate the Working of Keyword long

// C Program To Demonstrate the Working of Keyword long 
#include <stdio.h>
int main(){
    int a;
    long b;
    long long c;
    double d;
    long double e;
    
    // Displays Output
    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(d));
    printf("Size of long double = %ld bytes", sizeof(e));
    
    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

How Does This Program Work ?

    int a;
    long b;
    long long c;
    double d;
    long double e;

In this example, we have declared 5 variables a, b, c, d and e. Each having different data types such as int, long, long long, double and long double respectively.

    // Displays Output
    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(d));
    printf("Size of long double = %ld bytes", sizeof(e));

Then, we have used the sizeof() operator to find the size of int, long, long long, double and long double variables.

sizeof() operator is used to find the data size of different data types allocated to them.

In this case, as we can see long and long double variables are larger than int and double variables respectively.

Note: The long keyword cannot be used with float and char data types.

Some used terms are as follows:

#include <stdio.h> – In the first line we have used #include, it is a preprocessor command that tells the compiler to include the contents of the stdio.h(standard input and output) file in the program. 

The stdio.h is a file which contains input and output functions like scanf() and printf() to take input and display output respectively. 

Int main() – Here main() is the function name and int is the return type of this function. The Execution of any Programming written in C language begins with main() function. 

sizeof() – sizeof() operator is used to generate the storage size of an expression or a data type.

printf() – printf() function is used to display and print the string under the quotation to the screen.

// – Used for Commenting in C 

Conclusion

I hope after going through this tutorial, you understand the working of keyword long and how to use this keyword in your program.

If you still have any doubt regarding this, feel free to contact us in the Comment Section. We will be delighted to help you.

Leave a Comment

Your email address will not be published.