
- C Programming Tutorial
- C - Home
- C - Overview
- C - Environment Setup
- C - Program Structure
- C - Basic Syntax
- C - Data Types
- C - Variables
- C - Constants
- C - Storage Classes
- C - Operators
- C - Decision Making
- C - Loops
- C - Functions
- C - Scope Rules
- C - Arrays
- C - Pointers
- C - Strings
- C - Structures
- C - Unions
- C - Bit Fields
- C - Typedef
- C - Input & Output
- C - File I/O
- C - Preprocessors
- C - Header Files
- C - Type Casting
- C - Error Handling
- C - Recursion
- C - Variable Arguments
- C - Memory Management
- C - Command Line Arguments
- C Programming useful Resources
- C - Questions & Answers
- C - Quick Guide
- C - Useful Resources
- C - Discussion
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
", sizeof(int)); printf("Size of long : %ld Bytes
", 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 Articles
- Is there any need of “long” data type in C and C++?
- Which MySQL data type is used for long decimal?
- size_t data type in C
- Data type of character constants in C and C++
- What is the size of int, long type in C++ standard?
- What is data type of FILE in C?
- Hexadecimal literal of type long in Java
- What are primitive data type in C++?
- C++ Program to Convert long Type Variables to int
- C++ Program to Convert int Type Variables to long
- What is the size of int, long type as per C++ standard?
- Data Type Ranges and their macros in C++
- What is enumerated data type in C language?
- Generate Random Long type numbers in Java
- C++ Program for sorting variables of any data type
