1

i wrote this code:

#include <iostream>

using namespace std;

int main()
{
    int a;
    long int  b;
    
    cout << sizeof(a) << endl; /*output : 4 bytes */
    cout << sizeof(b) << endl; /* output : 4 bytes */
        return 0;
}

im using windows 10 64 bits operation system and i found this , but when i tried online compiler it shows diffrent : sizeof(int) == 4 bytes ; sizeof(long int) == 8 bytes why this ?? and how it works on other operation systems like linux ..... my greeting <3

  • duplicates: [Why are C++ int and long types both 4 bytes?](https://stackoverflow.com/q/13398630/995714), [C/C++: sizeof(short), sizeof(int), sizeof(long), sizeof(long long), etc... on a 32-bit machine versus on a 64-bit machine](https://stackoverflow.com/q/20109984/995714), [sizeof(long) in 64-bit C++](https://stackoverflow.com/q/7607502/995714), [Why is the sizeof(int) == sizeof(long)?](https://stackoverflow.com/q/18901080/995714), [Can I assume the size of long int is always 4 bytes?](https://stackoverflow.com/q/35844586/995714) – phuclv Jan 28 '22 at 16:12
  • 2
    To add some context, it made the porting of win32 applications to win64 much simpler. So it seemed like a good idea at the time. Note that `long` and `int` are formally different types, even if they have the same size and complementing scheme. – Bathsheba Jan 28 '22 at 16:25

0 Answers0