选择x ++或x--?
我有一个递增x的函数:
void fun(int arg){
int x = 10;
x ++;
}
在某种程度上可以根据参数''arg'将''x ++''更改为''x--'' '。
或者我必须做一个if语句吗?
I have a function that increments x:
void fun(int arg) {
int x = 10;
x++;
}
is there someway to change ''x++'' to ''x--'' based on the argument ''arg''.
Or do I have to make an if statement?
desktop写道:
desktop wrote:
我有一个递增x的函数:
void fun(int arg){
int x = 10;
x ++;
}
可以将''x ++''改为''x- - ''基于论证''arg''。
或者我是否必须发表if语句?
I have a function that increments x:
void fun(int arg) {
int x = 10;
x++;
}
is there someway to change ''x++'' to ''x--'' based on the argument ''arg''.
Or do I have to make an if statement?
void fun(int arg){int x = 10; x + = arg; }
fun(1); //增量
fun(-1); //减少
或
void fun(int arg){
int x = 10;
switch(arg){
case 0:
x ++;
break;
case 1:
x--;
}
}
fun(0); // inc
fun(1); // dec
但if有什么问题?
-
SM
rot13 for email
void fun(int arg) { int x = 10; x += arg; }
fun(1); //increment
fun(-1); //decrement
or
void fun(int arg) {
int x = 10;
switch(arg) {
case 0:
x++;
break;
case 1:
x--;
}
}
fun(0); //inc
fun(1); //dec
But what''s wrong with an if?
--
SM
rot13 for email
在2007-10-03 16:53,desktop写道:
On 2007-10-03 16:53, desktop wrote:
I有一个递增x的函数:
void fun(int arg){
int x = 10;
x ++;
}
是基于参数''arg'将''x ++'改为''x--'' '。
或者我必须做一个if语句吗?
I have a function that increments x:
void fun(int arg) {
int x = 10;
x++;
}
is there someway to change ''x++'' to ''x--'' based on the argument ''arg''.
Or do I have to make an if statement?
你的意思是如果arg小于0你想要减去它吗?
x< 0? --x:++ x;
如果(x
相同/>
--x;
其他
++ x;
-
Erik Wikstr ?? m
You mean if arg is less then 0 you want to decrement it instead?
x < 0 ? --x : ++x;
It is more or less the same thing as
if (x < 0)
--x;
else
++x;
--
Erik Wikstr??m
Erik Wikstr?m写道:
Erik Wikstr?m wrote:
2007-10- 03 16:53,desktop写道:
On 2007-10-03 16:53, desktop wrote:
>我有一个增加x的函数:
void fun(int arg){
int x = 10;
x ++;
}
是否可以将''x ++''改为''x--''为基础关于争论
''arg''。或者我必须做一个if语句?
>I have a function that increments x:
void fun(int arg) {
int x = 10;
x++;
}
is there someway to change ''x++'' to ''x--'' based on the argument
''arg''. Or do I have to make an if statement?
你的意思是如果arg小于0你想要减少它吗?
x< 0? --x:++ x;
You mean if arg is less then 0 you want to decrement it instead?
x < 0 ? --x : ++x;
arg< 0? --x:++ x;
arg < 0 ? --x : ++x;
>
这或多或少与
相同>
if(x< 0)
>
It is more or less the same thing as
if (x < 0)
if(arg< 0)
if (arg < 0)
--x;
else
++ x;
--x;
else
++x;
V
-
请在通过电子邮件回复时删除资金'A'
我没有回复最热门的回复,请不要问
V
--
Please remove capital ''A''s when replying by e-mail
I do not respond to top-posted replies, please don''t ask