ç递增/递减运算符 [英] C increment/decrement operators

查看:142
本文介绍了ç递增/递减运算符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

确定每个变量的值。所有变量都在执行前值5。

Determine the value of each variable after calculation is performed. All variables have value 5 before execution.


  1. A1 / = + B1 / - C1

  2. A2 + = + B2%C2 -

  1. A1/=++B1/--C1
  2. A2+=++B2%C2--

请告诉我这项工作如何

推荐答案

变量:

int A1 = 5;
int B1 = 5;
int C1 = 5;

int A2 = 5;
int B2 = 5;
int C2 = 5;

您code:

A1 /= ++B1 / --C1;
A2 += ++B2 % C2--;

可能会编译成类似的东西太多:

Will probably compile into something similar too:

++B1;
--C1;
A1 /= B1 / C1;

++B2;
A2 += B2 % C2;
C2--;

您可以输出使用编译器ASM,与海湾合作委员会及其-S标志。下面是我的电脑上的GCC ASM输出(我加了注释):

You can output the ASM using your compiler, with GCC its the -S flag. Here is the ASM output with GCC on my computer (I added the comments):

movl    $5, -20(%rbp) // A1 = 5
movl    $5, -24(%rbp) // B1 = 5
movl    $5, -28(%rbp) // C1 = 5
movl    $5, -32(%rbp) // A2 = 5
movl    $5, -36(%rbp) // B2 = 5
movl    $5, -40(%rbp) // C2 = 5

然后为第一个计算,这是执行(简化为了更容易理解注释):

Then for the first one calculation, this is performed (comments simplified for easier understanding):

addl    $1, -24(%rbp)      // ++B1
subl    $1, -28(%rbp)      // --C1
movl    -24(%rbp), %eax    // 
cltd
idivl   -28(%rbp)          // divide B1 by C1
movl    %eax, %esi         // 
movl    -20(%rbp), %eax    // 
cltd
idivl   %esi               // divide A1 by the previous
movl    %eax, -20(%rbp)

这篇关于ç递增/递减运算符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆