What is the size of int, long type as per C++ standard?


Here we will see what are the sizes of the int and long type data in C++. The sizes are depending on the system architecture and the Operating system.

So in the 32-bit system, the standard is ILP32. In this standard the int, long and the pointer variables are of 32-bits.

For the 64-bit system there are two variations. For Linux Operating system the standard is LP64. Here long and pointer are of 64-bits, but int are of 32-bits. For the Windows operating system, the standard is LLP64. Here long long is 64-bit, but int and long are of 32-bits.

Example

#include <iostream>
using namespace std;
int main() {
   cout << "Size of int: " << sizeof(int) * 8 << " bits" << endl;
   cout << "Size of long: " << sizeof(long) * 8 << " bits" <<endl;
   cout << "Size of long long: " << sizeof(long long) * 8 << " bits"<< endl;
}

Output

Size of int: 32 bits
Size of long: 32 bits
Size of long long: 64 bits

karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know

Updated on: 30-Jul-2019

315 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements