【发布时间】:2021-01-24 10:16:00
【问题描述】:
当我运行这段代码时,一切都很好,但是 a /= 10; 的值;输出是 10,10 是错误答案正确答案是 1。
// C program to demonstrate
// working of Assignment operators
#include <stdio.h>
int main()
{
// Assigning value 10 to a
// using "=" operator
int a = 10;
printf("Value of a is %d\n", a);
// Assigning value by adding 10 to a
// using "+=" operator
a += 10;
printf("Value of a is %d\n", a);
// Assigning value by subtracting 10 from a
// using "-=" operator
a -= 10;
printf("Value of a is %d\n", a);
// Assigning value by multiplying 10 to a
// using "*=" operator
a *= 10;
printf("Value of a is %d\n", a);
// Assigning value by dividing 10 from a
// using "/=" operator
a /= 10;
printf("Value of a is %d\n", a);
return 0;
}
但是当我运行这段代码时
#include <stdio.h>
int main()
{
int a = 10;
a /= 10;
printf("Value of a is %d\n", a);
return 0;
}
**the output is 1 but how please help me.**
【问题讨论】:
-
为什么你认为应该是
1?printf输出显示为除法前的值是什么? -
10/10= 结果应该是什么? -
100/10=10。使用您最喜欢的调试器单步执行代码。
标签: c operators variable-assignment