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

Long integer data type is required in C language

WBOY
Release: 2023-09-19 13:09:03
forward
807 people have browsed it

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));
}
Copy after login

Output

Size of int : 4 Bytes
Size of long : 4 Bytes
Size of long long : 8 Bytes
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template