

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Need of long data type in C
In C or C++, there are four different datatypes, that are used for integer type data. These four datatypes are short, int, long and long long. Each of these datatypes takes different memory spaces. The size varies in different architecture and different operating systems. Sometimes int takes 4-bytes or sometimes it takes 2-bytes. This also happen for the compilers. So we can use cross compilers.
The cross compilers are basically a compiler, which is capable of compiling for a platform other than current platform.
So if we want to compile the following code in 32bit system, and 64-bit system, it will generate different outputs.
Example
#include<stdio.h> int main() { printf("Size of int : %ld Bytes\n", sizeof(int)); printf("Size of long : %ld Bytes\n", 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 datatype varies from compiler. So what is the reason behind it?
The CPU calls data from primary memory (RAM) by providing the address of Memory Address Register (MAR). When the location is found, it is transferred to Memory Buffer Register (MBR). The data is stored into the CPU register for further usage. So the size of data bus determines the size of CPU register. For 32-bit system, it can call only 4-byte data at a time. If data is larger than 32bit, then it will take two cycles. So for smaller data it does not make any difference.
- Related Questions & Answers
- Is there any need of “long” data type in C and C++?
- Which MySQL data type is used for long decimal?
- Hexadecimal literal of type long in Java
- What is the size of int, long type in C++ standard?
- size_t data type in C
- What is the size of int, long type as per C++ standard?
- Generate Random Long type numbers in Java
- Data type of character constants in C and C++
- What is long long in C/C++?
- What is data type of FILE in C?
- Need for DMA data transfer
- Create BigInteger via long type variable in Java
- Why do we need Data Encryption?
- What are primitive data type in C++?
- C++ Program for sorting variables of any data type