比较类似术语之间的差异

Difference Between

家 / Technology / IT / Programming /int和long之间的差异

int和long之间的差异

March 1, 2018Posted byLithmee

关键区别 - 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.

int和long之间的差异

Figure 01: Java program with int values

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,长,浮动,双重中。当将较大的数据类型分配给小数据类型时,有必要进行铸造。

int和long_figure 02之间的差异

Figure 02: Casting

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.

Key Difference Between int and long

图03:具有较长值的Java程序

根据上述程序,宽度和长度是长变量。结果值分配给一个长变量。长期是最大的数据类型。其他数据类型比长度小。因此,其他数据类型可以分配给长时间而无需打字。在为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

相关文章:

Difference Between C and C++ Difference Between Directed and Undirected Graph Difference Between calloc and mallocDifference Between calloc and malloc Difference Between AWT and SwingDifference Between AWT and Swing Difference Between throw and throws in JavaDifference Between throw and throws in Java

Filed Under:Programming标记为:比较int和长时间,int,intand long Differences,INT和长期相似之处,intBytes,int定义,intKeywords,int max值,int min值,int vslong,long,long Bytes,长定义,long Keywords,长最大值,long Min Value

关于the Author:Lithmee

Lithmee Mandula是计算机系统工程的孟加(荣誉)。她目前正在攻读计算机科学硕士学位。她在写作和研究方面的兴趣领域包括编程,数据科学和计算机系统。

发表评论取消回复

Your email address will not be published.Required fields are marked*

请求文章

Featured Posts

Difference Between Coronavirus and Cold Symptoms

Difference Between Coronavirus and Cold Symptoms

冠状病毒和SARS之间的差异

冠状病毒和SARS之间的差异

Difference Between Coronavirus and Influenza

Difference Between Coronavirus and Influenza

冠状病毒和covid 19之间的差异

冠状病毒和covid 19之间的差异

你可能喜欢

橙色和橘子之间的差异

Difference Between Acid and Acidic

Difference Between Acid and Acidic

Difference Between England and British

冷冻断裂和冻结蚀刻之间的差异

冷冻断裂和冻结蚀刻之间的差异

空间分类和自然选择有什么区别

空间分类和自然选择有什么区别

最新的帖子

  • What is the Difference Between Soil Air and Atmospheric Air
  • What is the Difference Between Hotplate and Induction Cooker
  • What is the Difference Between Steroids and Antibiotics
  • What is the Difference Between Gastritis and Pancreatitis
  • What is the Difference Between Normal Air and Nitrogen in Tires
  • 痤疮和酒渣鼻有什么区别
  • 家
  • Vacancies
  • 关于
  • 请求文章
  • 联系我们

Copyright © 2010-2018Difference Between. All rights reserved.Terms of Use和隐私政策:合法的.