w3resource logo


C Programming Exercises

C Exercises: Demonstrate the working of keyword long

Secondary Nav

C Variable Type : Exercise-18 with Solution

Write a C program to demonstrate the working of keyword long.

Expected Output :

 The size of int = 4 bytes                                                           
 The size of long = 8 bytes                                                          
 The size of long long = 8 bytes                                                     
 The size of double = 8 bytes                                                        
 The size of long double = 16 byte 

C Code:

#include<stdio.h>

int main()
{
    int a;
    long b;
    long long c;

    double e;
    long double f;
    printf("\n Demonstrate the working of keyword long \n");
    printf("------------------------------------------\n");

    printf(" The size of int = %ld bytes \n", sizeof(a));
    printf(" The size of long = %ld bytes\n", sizeof(b));
    printf(" The size of long long = %ld bytes\n", sizeof(c));

    printf(" The size of double = %ld bytes\n", sizeof(e));
    printf(" The size of long double = %ld bytes\n\n", sizeof(f));

    return 0;
}

Solution


#include<stdio.h>

int main()
{
    int a;
    long b;
    long long c;

    double e;
    long double f;
    printf("\n Demonstrate the working of keyword long \n");
    printf("------------------------------------------\n");

    printf(" The size of int = %ld bytes \n", sizeof(a));
    printf(" The size of long = %ld bytes\n", sizeof(b));
    printf(" The size of long long = %ld bytes\n", sizeof(c));

    printf(" The size of double = %ld bytes\n", sizeof(e));
    printf(" The size of long double = %ld bytes\n\n", sizeof(f));

    return 0;
}

Improve this sample solution and post your code through Disqus



Join our Question Answer community to learn and share your programming knowledge.

Help the community:

Python: Fizzbuzz

C++: Decimal to binary conversion

JavaScript: Need Help in JavaScript

Python: Help me with this program