+ 1

What's the difference between short,int and long?

21st Apr 2018, 3:06 PM
Ziyad Aldoumany
Ziyad Aldoumany - avatar
2 Respostas
+ 10
Well the difference is very small but can be very important in some instances. When programming the second most important objective (after making the program do what it is supposed to) is saving memory to make the program run as fast as possible. This is where your keyword "long" comes in. long is an integer but integer isn't exactly a long understand? There is also a "short". now usually these are referenced with int after them but it is not required. The main difference between them is their size. Depending on the computer but in most cases a "short" is two bytes a "long" is four bytes and an "int" can be two or four bytes. It is important in programs that you declare it short or long if you know exactly how big the number is going to be and how often it is going to modified so that you can save as much memory as possible. Now as far as the range that depends on the size of the int whether it is two or four bytes. Here is a table to reference sizes and values. type size range short int 2 bytes -32,768 to 32,767 long int 4 bytes -2,147,483,648 to 2,147,483,647 int (16 bit) 2 bytes -32,768 to 32,767 int (32 bit) 4 bytes -2,147,483,648 to 2,147,483,647 SOURCE: https://www.quora.com/What-is-the-difference-between-short-int-and-long-int-data-types-and-float-double-data-type
21st Apr 2018, 3:42 PM
Baraa AB
Baraa AB - avatar
+ 5
sizeof(short) <= sizeof(int) <= sizeof(long) long can store the largest numbers.
21st Apr 2018, 3:11 PM
Timon Paßlick