【发布时间】:2019-04-17 05:55:06
【问题描述】:
#include<string.h>
#include<limits.h>
using namespace std;
void v6(char rq,int &cost)
{
if(rq=='2')
cost+=1;
if(rq=='1')
cost+=2;
if(rq=='3')
cost+=3;
}
int main()
{
int cost=0;
v6(2,cost);
cout<<cost;
}
输出:
0
但是,c 的值(通过引用传递)并没有改变;请解释一下。
也使用过指针,但无济于事
【问题讨论】:
-
您将
2传递为int而不是char,因此函数中的条件不成立。调用 v6 为v6('2',control,cost); -
@Wander3r 你可以添加这个作为答案。