当前位置:网站首页>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 .
边栏推荐
- 第五期个人能力认证考核通过名单公布
- Leetcode topic [array] - 119 Yang Hui triangle II
- PMP每日一练 | 考试不迷路-7.6
- 包装行业商业供应链管理平台解决方案:布局智慧供应体系,数字化整合包装行业供应链
- tensorflow和torch代码验证cuda是否安装成功
- R language ggplot2 visualization: use ggviolin function of ggpubr package to visualize violin diagram
- 【pytorch】yolov5 训练自己的数据集
- 如何提高网站权重
- Word如何显示修改痕迹
- R语言dplyr包进行数据分组聚合统计变换(Aggregating transforms)、计算dataframe数据的分组均值(mean)
猜你喜欢

A popular explanation will help you get started

Solution of commercial supply chain management platform for packaging industry: layout smart supply system and digitally integrate the supply chain of packaging industry

About NPM install error 1

中缀表达式转后缀表达式详细思路及代码实现

快速幂模板求逆元,逆元的作用以及例题【第20届上海大学程序设计联赛夏季赛】排列计数

Pychrm Community Edition calls matplotlib pyplot. Solution of imshow() function image not popping up

Synchronous development of business and application: strategic suggestions for application modernization

史上超级详细,想找工作的你还不看这份资料就晚了

How word displays modification traces

The list of people who passed the fifth phase of personal ability certification assessment was published
随机推荐
[translation] a GPU approach to particle physics
AUTOCAD——中心线绘制、CAD默认线宽是多少?可以修改吗?
Pychrm Community Edition calls matplotlib pyplot. Solution of imshow() function image not popping up
The second day of rhcsa study
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
R language ggplot2 visualization: use the ggdotplot function of ggpubr package to visualize dot plot, set the palette parameter, and set the colors of data points and box graphs of dot plots at differ
usb host 驱动 - UVC 掉包
R language ggplot2 visualization: use ggviolin function of ggpubr package to visualize violin diagram
A full set of teaching materials, real questions of Android interview of 7 major manufacturers including Alibaba Kwai pinduoduo
黑馬--Redis篇
AutoCAD - what is the default lineweight for centerline drawing and CAD? Can I modify it?
MRO工业品企业采购系统:如何精细化采购协同管理?想要升级的工业品企业必看!
How to type multiple spaces when editing CSDN articles
提前解锁 2 大直播主题!今天手把手教你如何完成软件包集成?|第 29-30 期
Pytorch common loss function
JDBC详解
Tensorflow and torch code verify whether CUDA is successfully installed
R language ggplot2 visual time series histogram: visual time series histogram through two-color gradient color matching color theme
How word displays modification traces
打家劫舍III[后序遍历与回溯+动态规划]