当前位置:网站首页>short i =1; I=i+1 and short i=1; Difference of i+=1
short i =1; I=i+1 and short i=1; Difference of i+=1
2022-07-06 19:20:00 【qq_ thirty-seven million seven hundred and five thousand five h】
short i =1; i=i+1 And short i=1; i+=1 The difference between
It's typical to arrive JAVA Basic interview questions , I met in the last interview , Now take a note of .
short i =1; i=i+1;
short i=1;i+=1;
What's the difference between the two ?
When performing arithmetic operations on variables of two data types with different capacities ,java It will automatically improve the accuracy of small volume variables , And then we do the calculation , The result type obtained is the promoted large-capacity data type . If the result is assigned to a variable of small data type , You must perform forced type conversion , Otherwise, the compiler will report a loss of accuracy error . For example, the landlord , use i To express 1:
short s1 = 1;
int i = 1;
First , because short The type is 16 Bit , and int The type is 32 Bit , It's going on
(s1+i) Operation time , Automatically put s1 Upgrade to 32 position , Then with i Add up , And what you get is 32 Bit , And then
s1=s1+i; Must report wrong , Because if the assignment succeeds , Just lower 16 Bit is assigned to s1, Although this is exactly what the landlord wants , But the compiler cannot determine what your intention is .
Execute forced transfer :
s1=(short)(s1+i); That's fine .
s1+=i; It can compile and get correct results , and s1=s1+i; But report a mistake , Because they are not equivalent ,s1+=i The way java Would be right i Narrow conversion , Automatically executed by the compiler .
边栏推荐
- 助力安全人才专业素养提升 | 个人能力认证考核第一阶段圆满结束!
- Php+redis realizes the function of canceling orders over time
- Swagger2 reports an error illegal DefaultValue null for parameter type integer
- Unlock 2 live broadcast themes in advance! Today, I will teach you how to complete software package integration Issues 29-30
- ACTF 2022圆满落幕,0ops战队二连冠!!
- How to type multiple spaces when editing CSDN articles
- GCC [7] - compilation checks the declaration of functions, and link checks the definition bugs of functions
- R语言使用dt函数生成t分布密度函数数据、使用plot函数可视化t分布密度函数数据(t Distribution)
- R language ggplot2 visualization: use ggviolin function of ggpubr package to visualize violin diagram
- R language uses the order function to sort the dataframe data, and descending sorting based on a single field (variable)
猜你喜欢
When visual studio code starts, it prompts "the code installation seems to be corrupt. Please reinstall." Solution to displaying "unsupported" information in the title bar
About NPM install error 1
Actf 2022 came to a successful conclusion, and 0ops team won the second consecutive championship!!
Intelligent supply chain management system solution for hardware and electromechanical industry: digital intelligent supply chain "creates new blood" for traditional industries
php+redis实现超时取消订单功能
Word如何显示修改痕迹
通俗的讲解,带你入门协程
[depth first search] Ji suanke: Square
AIRIOT物联网平台赋能集装箱行业构建【焊接工位信息监控系统】
渲大师携手向日葵,远控赋能云渲染及GPU算力服务
随机推荐
驼峰式与下划线命名规则(Camel case With hungarian notation)
How word displays modification traces
Tensorflow and torch code verify whether CUDA is successfully installed
Word如何显示修改痕迹
ROS自定义消息发布订阅示例
openmv4 学习笔记1----一键下载、图像处理背景知识、LAB亮度-对比度
关于图像的读取及处理等
RT-Thread 组件 FinSH 使用时遇到的问题
Characteristic colleges and universities, jointly build Netease Industrial College
R语言ggplot2可视化:使用ggpubr包的ggstripchart函数可视化分组点状条带图(dot strip plot)、设置add参数为不同水平点状条带图添加箱图
Multithreading Basics: basic concepts of threads and creation of threads
First day of rhcsa study
swagger2报错Illegal DefaultValue null for parameter type integer
五金机电行业智能供应链管理系统解决方案:数智化供应链为传统产业“造新血”
Interview assault 63: how to remove duplication in MySQL?
Translation D28 (with AC code POJ 26:the nearest number)
Openmv4 learning notes 1 --- one click download, background knowledge of image processing, lab brightness contrast
R语言使用order函数对dataframe数据进行排序、基于单个字段(变量)进行降序排序(DESCENDING)
Elastic search indexes are often deleted [closed] - elastic search indexes gets deleted frequently [closed]
USB host driver - UVC swap