为什么一个个单独算答案对,可是弄一起,答案就错了.比如第一个答案应该是5啊,出来的却是7?#include using namespace std;int main (){int Cost = 5 ;int Price = 10 ;{int a = ++Cost;int b = Cost++; int c = Cost = Price++;int
来源:学生作业帮助网 编辑:六六作业网 时间:2025/01/29 07:32:25
为什么一个个单独算答案对,可是弄一起,答案就错了.比如第一个答案应该是5啊,出来的却是7?#include using namespace std;int main (){int Cost = 5 ;int Price = 10 ;{int a = ++Cost;int b = Cost++; int c = Cost = Price++;int
为什么一个个单独算答案对,可是弄一起,答案就错了.比如第一个答案应该是5啊,出来的却是7?
#include
using namespace std;
int main ()
{
int Cost = 5 ;
int Price = 10 ;
{
int a = ++Cost;
int b = Cost++;
int c = Cost = Price++;
int d = Cost = ++Price;
int e = Price++ + ++Price;
int f = Cost += Price;
int g = Cost *=5;
int h = Cost += Price * 5;
int i = a++; //i = ++Cost++ ;
int j = b++; // j = Cost = ++Price++;
int k = Price /= Cost++ ;
cout
为什么一个个单独算答案对,可是弄一起,答案就错了.比如第一个答案应该是5啊,出来的却是7?#include using namespace std;int main (){int Cost = 5 ;int Price = 10 ;{int a = ++Cost;int b = Cost++; int c = Cost = Price++;int
int a = ++Cost;//a=6,cost=6
int b = Cost++; //b=6,cost=7
int c = Cost = Price++;//c=10,cost=10,price=11
int d = Cost = ++Price;//d=12,cost=12,price=12
int e = Price++ + ++Price;//e=26,price=14
int f = Cost += Price;//f=26,cost=26
int g = Cost *=5;//g=130,cost=130
int h = Cost += Price * 5;//h=200,cost=200
int i = a++; //i=6,a=7
int j = b++; // j=6,b=7
int k = Price /= Cost++ ;//k=0(14/200),price=0(14/200),cost=201
其实就是两点,b=++a是a+1,然后把值给b,b=a++是先把a的值给b,然后再+1
和同一行的运算中先从右边开始算(e那个,如果把加好改成减号就看出区别了)
你正确。答案错了。要不就是题目出错了。
来自英语牛人团、计算机牛人团
望采纳 O(∩_∩)O谢谢
大晚上的答个题不容易啊。。。。望采纳啊(就是点一下"选为满意答案")。。。。