int a=0, b=0, c=0;c=(a-=a-5), (a=b, b+3); printf(“%d,%d,%d\n”,a, b, c);分析程序,得出结果
时间: 2024-05-15 11:12:13 浏览: 13
首先,先看一下这个表达式:
```c
c = (a -= a - 5), (a = b, b + 3);
```
这里使用了逗号运算符,逗号运算符会依次计算它的每个操作数,然后返回最后一个操作数的值。因此,这个表达式的执行顺序如下:
1. `a -= a - 5`,相当于 `a = a - (a - 5)`,即 `a = 5`,此时 `a` 的值为 5。
2. `(a = b, b + 3)`,先执行 `a = b`,将 `b` 的值赋给 `a`,即 `a = 0`,然后计算 `b + 3`,但是这个结果没有被使用,因为逗号运算符只返回最后一个操作数的值。
因此,最终的结果是:
```c
a = 5, b = 0, c = 5
```
执行 `printf("%d,%d,%d\n", a, b, c);` 会输出 `5,0,5`。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![](https://img-home.csdnimg.cn/images/20210720083646.png)
![-](https://csdnimg.cn/download_wenku/file_type_lunwen.png)
![-](https://csdnimg.cn/download_wenku/file_type_lunwen.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://img-home.csdnimg.cn/images/20210720083646.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![-](https://csdnimg.cn/download_wenku/file_type_lunwen.png)
![-](https://csdnimg.cn/download_wenku/file_type_lunwen.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://img-home.csdnimg.cn/images/20210720083646.png)
![](https://img-home.csdnimg.cn/images/20210720083646.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)