Difference between long and int data types

Alex picture Alex · May 23, 2009 · Viewed 108.3k times · Source

Considering that the following statements return 4, what is the difference between the int and long types in C++?

sizeof(int)
sizeof(long)

Answer

Paul Sonier picture Paul Sonier · May 23, 2009

From this reference:

An int was originally intended to be the "natural" word size of the processor. Many modern processors can handle different word sizes with equal ease.

Also, this bit:

On many (but not all) C and C++ implementations, a long is larger than an int. Today's most popular desktop platforms, such as Windows and Linux, run primarily on 32 bit processors and most compilers for these platforms use a 32 bit int which has the same size and representation as a long.