English

Differentiate between the following: int and long

Advertisements

Question

Differentiate between the following:

int and long

Distinguish Between
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 int data type is suitable for storing integer values within the 32-bit range.

4. The long data type is suitable for storing large integer values beyond the range of int.

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: int a = 1000;

6. Example: long a = 10000000000L;

shaalaa.com
  Is there an error in this question or solution?
Chapter 6: Variables and Expressions - EXERCISE [Page 132]

APPEARS IN

Dheeraj Mehrotra Computer Science [English] Class 12
Chapter 6 Variables and Expressions
EXERCISE | Q 30. (c) | Page 132
Advertisements
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×