返回信息流代码结构如下:
int fun(int type)
{
switch(type)
{
case 1:
return a;
case 2:
return b;
...
default:
return 0;
}
}
在这种情况是直接用return返回,还是先保存结果使用break最后返回(如下)?
求问在 效率 和 代码规范 等方面有什么区别?
int fun(int type)
{
int tmp(0);
switch(type)
{
case 1:
tmp=a;
break;
case 2:
tmp=b;
break;
...
default:
tmp=0;
break;
}
return tmp;
}
通过『我邮2.0』发布
这是一条镜像帖。来源:北邮人论坛 / cpp / #91808同步于 2016/5/23
该镜像源已超过 30 天没有更新,可能在源站已被删除。
CPP机器人发帖
请教c++ switch中break return选用问题
megeee
2016/5/23镜像同步5 回复
订阅后,新回复会通过你的通知中心匿名送达。
5 条回复