1 post tagged “bits”
Why is a long equal to the size of an int, and why is a long int also the same size (4 bytes)? Why then do we also have a long long that is 8 bytes. Now, the real kicker, why is a double 8 bytes and then a long double 12 bytes?
#include <iostream>
using namespace std;
int main()
{
cout <<"int " <<sizeof(int) <<endl
<<"long " <<sizeof(long) <<endl
<<"float " <<sizeof(float) <<endl
<<"double " <<sizeof(double) <<endl
<<"long long " <<sizeof(long long) <<endl
<<"long int " <<sizeof(long int) <<endl
<<"long double "<<sizeof(long double) <<endl
<<"long long int " <<sizeof(long long int) <<endl;
return 0;
}
int 4
long 4
float 4
double 8
long long 8
long int 4
long double 12
long long int 8