Differentiate between the following: int and long
Advertisements
Question
Differentiate between the following:
int and long
Advertisements
Solution
|
int |
long |
|---|---|
|
1. The int data type is used to store integer values of a smaller range in Java. |
1. The long data type is used to store integer values of a larger range in Java. |
|
2. The int data type occupies 4 bytes (32 bits) of memory. |
2. The long data type occupies 8 bytes (64 bits) of memory. |
|
3. The range of int is −2,147,483,648 to 2,147,483,647. |
3. The range of long is −9,223,372,036,854,775,808 to 9,223,372,036,854,775,807. |
|
4. The |
4. The |
|
5. Integer literals within the int range are treated as int by default. |
5. A long integer literal can be specified using the suffix L or l. |
|
6. Example: |
6. Example: |
