C 中的递减混淆

问题描述

我收到了一个 C 脚本,但递减时发生了一些奇怪的事情,我需要帮助才能知道它为什么不起作用。

#include <stdio.h>

int main()
{
    int a = 10;
    a=a--;
    printf("test %d\n",a);

    return 0;
}

在我的脑海中,脚本是这样的:

  1. 将 a 定义为值为 10 的整数。
  2. 从 a 中检索 10。
  3. 将 10 分配给 a。
  4. 将 a 减 1。
  5. 打印“测试 9”。
  6. 计划结束。

但是当我运行它时:

test 10

这很奇怪,我以为是 9。

然后我尝试使用稍后...

#include <stdio.h>

int main()
{
    int a = 10;
    a=a--;
    printf("test1 %d\n",a);
    
    int j = a;
    printf("test2 %d\n",j);
    
    return 0;
}

但还是 10:

test1 10
test2 10

为什么会这样?递减似乎没有任何作用...

预先感谢您的帮助。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)