Working of Keyword long in C programming

long is a keyword in Java that symbolises the Long datatype. The long data type is a 64-bit two’s complement integer with:

Output of 64 bit GCC compiler would give the size of long as 8 whereas on 32 bit GCC compiler the size would be 4. So it varies from compiler to compiler. Now the question is what exactly is happening here? Let’s discuss it in the way of how compiler allocates memory internally.

CPU calls data from RAM by giving the address of the location to MAR (Memory Address Register). The location is found and the data is transferred to MDR (Memory Data Register). This data is recorded in one of the Registers in the Processor for further processing. That’s why size of Data Bus determines the size of Registers in Processor. Now, a 32 bit register can call data of 4 bytes size only, at a time. And if the data size exceeds 32 bits, then it would required two cycles of fetching to have the data in it. This slows down the speed of 32 bit Machine compared to 64 bit, which would complete the operation in ONE fetch cycle only. So, obviously for the smaller data, it makes no difference if my processors are clocked at the same speed. Compilers are designed to generate the most efficient code for the target machine architecture.

Note: Interestingly we don’t have any need of “long” data type as their replacement(int, long long) is already available from C99 standard.

In the below program, all the possible variables with long datatype are defined and their sizes are calculated and print using sizeof() operator.

Below is the C program to find the demonstrate working of long keyword:





// C program to demonstrate the working
// of long keyword
#include <stdio.h>
int main()
    long longType;
    int integerType;
    long int longIntegerType;
    long long int longLongIntegerType;
    float floatType;
    double doubleType;
    long double longDoubleType;
    // Calculate and Print the size of all variables
    printf("Size of longType is: %ld\n",
    printf("Size of integerType is: %ld\n",
    printf("Size of longIntegerType is: %ld\n",
    printf("Size of longLongIntegerType is: %ld\n",
    printf("Size of floatType is: %ld\n",
    printf("Size of doubleType is: %ld\n",
    printf("Size of longDoubleType is: %ld\n",
    return 0;


Size of longType is: 8
Size of integerType is: 4
Size of longIntegerType is: 8
Size of longLongIntegerType is: 8
Size of floatType is: 4
Size of doubleType is: 8
Size of longDoubleType is: 16

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

Content Manager at LambdaTest

If you like GeeksforGeeks and would like to contribute, you can also write an article using or mail your article to See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

Article Tags :
Practice Tags :