Java 前增 后增_Java中的前增量和后增量

本问题已经有最佳答案,请猛点这里访问。

我面临着发现是否可以做到的问题

int a=0,c=0,b;

case 1 a=a++;// in that case the value of a will be 0

case 2 a=++a;// in that case the value of a will be 1

case 3 b=c++;// in that case the value of b will be 0 but after the execution of

//the statement value of c will be 1 which it should be.

case 4 b=b+c;// here the value of b will be 1 means c will be 1 there and b will be 0

我的问题是,在第一种情况下,我们在同一变量中分配后递增值a,因此首先在a本身中分配初始值,但执行语句后,a的值不会像在c ++中那样递增 增量值的位置。 在第一种情况下,递增的a的地址和分配的a的地址是否可能会不同。

我搜索了stackoverflow,但无法找到问题的答案,尽管我发现这些链接在某种程度上很有帮助

后增量(i ++)和预增量(++ i)运算符在Java中如何工作?

Java之前和之后的增量和减量

我搜索了互联网,上面写着一些关于幽灵变量的信息,但我没有正确地获得它

所以请告诉我正确答案。

in first case we are assigning the post incremented value a in the

same variable so first it assigns the initial value in the a itself

but after the execution of the statement the value of a is not

incremented as it is in c++ so where that incremented value goes. Is

there any possibility that in first case address of the incremented a

and address of the assigned a will be different.

语句执行后,情况1的a值(情况3中的c的值相同)在表达式a++(或c++)执行后不会增加。 立即完成。

因此,在您的情况1中,a的值只是暂时在1求值a++之后的值。 该表达式的值虽然为零。 因此,在情况1中将a++的结果分配给a时,会将a重置为零。

至于问题的第二部分:不,要递增的a和要分配的a是完全相同的变量。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值