Home >Backend Development >C++ >Long integer data type is required in C language

Long integer data type is required in C language

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBforward
2023-09-19 13:09:03823browse

Long integer data type is required in C language

In C or C, there are four different data types for integer type data. The four data types are short, int, long, and long long. Each data type takes up different memory space. The size varies in different architectures and different operating systems. Sometimes an int requires 4 bytes, sometimes 2 bytes. This happens with compilers too. So we can use cross compiler.

A cross-compiler is basically a compiler that is capable of compiling for platforms other than the current platform.

So if we want to compile the following code, different output will be produced in 32-bit systems and 64-bit systems.

Example

#include<stdio.h>
int main() {
   printf("Size of int : %ld Bytes</p><p>", sizeof(int));
   printf("Size of long : %ld Bytes</p><p>", sizeof(long));
   printf("Size of long long : %ld Bytes", sizeof(long long));
}

Output

Size of int : 4 Bytes
Size of long : 4 Bytes
Size of long long : 8 Bytes

So, from this example we can easily understand that the long data type varies from compiler to compiler. So what’s the reason behind this?

CPU calls data in main memory (RAM) by providing the address of the memory address register (MAR). Once the location is found, it is transferred to the Memory Buffer Register (MBR). Data is stored into CPU registers for further use. So the size of the data bus determines the size of the CPU registers. For 32-bit systems, only 4 bytes of data can be called at a time. If the data is larger than 32bit, two cycles are required. So for smaller data there is no difference.

The above is the detailed content of Long integer data type is required in C language. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete