关键区别 - int vslong
In programming, it is required to store data. The data is stored in memory. Memory locations that can store data is called variables. Each memory location can store a specific type of data. Memory size for each data type is different. The int data type is used to store numeric values without decimal points. The float and double data types are used to store numerical values with decimal points. Thechar数据类型用于存储单个字符值。同样,每种数据类型都可以根据类型存储特定值。在编程语言中,例如python, it is not necessary to declare the variable type. If the programmer is written as a = 3, Python automatically identifies that it is an integer variable. In programming languages such asJava,the programmer should specify the data type. If the variable is declared as an int, then he cannot assign a character value to it. The int and long are two data types. This article discusses the difference between int and long. Thekey differencebetween int and long is thatint宽度为32位,而宽度为64位宽度。
内容
1.Overview and Key Difference
2.What is int
3.What is long
4.INT和长时间之间的相似之处
5.并排比较 - int vs long在表格形式中
6。概括
什么是INT?
A data type int is a most commonly used data type that holds an integer value in it. It is predefined data type supported by many programming languages such as Java. To declare an integer variable, the keyword ‘int’ is used. Therefore, it cannot be used as an identifier such as a variable name or a method name. Refer the below example program.
According to the above program, the variable a is an int and has the value 10. The variable b is an int and has the value 20. The sum of a and b are calculated and assigned to the variable sum. It is also an integer. In the for loop, ‘i’ is the counter variable. It is an integer. It will iterate 5 times. When the ‘i’ value becomes 6, the condition becomes false and get out of the loop.
可以在数据类型上执行打字。这是将一个数据类型转换为另一种数据类型的过程。当将较小的数据类型分配给较大的数据类型时,不需要铸造。扩大发生在一个字节,短,int,长,浮动,双重中。当将较大的数据类型分配给小数据类型时,有必要进行铸造。
In above program, the num1 variable has value 10. The variable num2 has value 20. The total is an int. As int is a larger data type than a byte, it is necessary to typecast into byte in order to store into a byte variable. If there is no typecasting, it means the integer value is assigned to the byte variable so there will be a compile-time error.
What is long?
The long is a predefined data type provided by languages such as Java. In Java, the data range is from -9,223,372,036,854,775,808(-2^63) to 9,223,372,036,854,775,807 (inclusive) (2^63-1). It is 64 bits in width. The number of bytes for a long is 8 bytes. One byte is equivalent to 8 bits. Refer the below program.
根据上述程序,宽度和长度是长变量。结果值分配给一个长变量。长期是最大的数据类型。其他数据类型比长度小。因此,其他数据类型可以分配给长时间而无需打字。在为int分配长的值时,需要打字。
int和long之间有什么相似之处?
- Both int and long are predefined data types supported by programming languages such as Java.
What is the Difference Between int and long?
int vslong |
|
INT数据类型是32位签名的两个补充整数。 | 长数据类型是64位签名的补充整数。 |
字节数 | |
int长4个字节。 | The long is 8 bytes long. |
最小值 | |
Minimum value of int is – 2,147,483,648 (-2^31) in Java | Minimum value of long is -9,223,372,036,854,775,808(-2^63) in Java |
Maximum Value | |
INT的最大值为2,147,483,647(包括)(2^31-1) | Maximum value of long is 9,223,372,036,854,775,807 (inclusive) (2^63-1) in Java |
Default Value | |
The default value of int is 0. | The default value of long is 0L. |
Keyword | |
The keyword ‘int’ is used to declare an integer. | The keyword ‘long’ is used to declare a long. |
Required Memory | |
The int requires less memory than long. | The long requires more memory than int. |
概括–int vslong
在编程中,有必要存储数据。这些数据存储在内存位置。这些内存位置称为变量。每个变量都有要存储的特定类型数据。有数据类型,例如int,char,double和float等。本文讨论了两种int和long的数据类型之间的差异。INT数据类型是32位签名的两个补充整数。长数据类型是64位签名的补充整数。长期是比INT更大的数据类型。int和长之间的区别在于,int的宽度为32位,而长为64位宽度。
Reference:
1.点,教程。“ Java基本数据类型。”Tutorials Point, 8 Jan. 2018.Available here
2.“Type conversion in Java with Examples.”GeeksforGeeks, 5 Jan. 2017.Available here
发表评论