嵌套条件运算符 [英] nested conditional operator

查看:140
本文介绍了嵌套条件运算符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我有一段代码:


int func(int flag)

{

int number = 1;

if(flag == 1)

return 0;

if (flag == 2)

if(number == 1)

返回0;

else

返回数字;

返回(数字);

}


我想用宏替换此函数。


int main(无效)

{

int result;

int flag = 0;

result = func(flag);

}


我尝试使用嵌套条件运算符将函数转换为

宏,但结束了

带来了一些问题。


有人可以帮帮我吗?


在此先感谢您的帮助....

解决方案

ju ********** @ yahoo.co.in 写道:

我有一块代码:

int func(int flag)
{
int number = 1;
if(flag == 1)
返回0;
if( flag == 2)
if(number == 1)
return 0;
else
返回号码;
返回(号码);
}


/真/这个代码?因为`number == 0`的测试似乎有点多余。

我想用宏替换这个函数。


为什么?

int main(无效)
{结果;
int flag = 0;
result = func(flag);
}
我试过使用嵌套的条件运算符将函数转换为
宏,但结束了一些问题。

任何人都可以帮我吗?




你还没有向我们展示你遇到问题的代码,而你/>
没有说出问题所在,所以这有点棘手。


请记住条件表达式是/表达式和

因此< fx:sob />不能包含声明。


-

Chris寻求者 Dollin

伸出隐藏在网络中的镜子。 - 文艺复兴,/奔跑/


ju ********** @ yahoo.co.in 写道:


大家好,

我有一段代码:

int func(int flag)
{
int number = 1;
if(flag == 1)
返回0 ;
if(flag == 2)
if(number == 1)
返回0;
否则
返回号码;
返回(号码) ;

我希望用宏替换这个函数。

int main(void)
{
int result;
int flag = 0;
result = func(flag);
我试过使用嵌套条件运算符将函数转换为
宏,但结束了
有一些问题。

任何人都可以帮我吗?




#define FUNC(f)(f == 1 || f == 2&& number == 0?0:number)


-

p ete


pete< pf ***** @ mindspring.com>写道:

if(flag == 2)
if(number == 1)
return 0;

#define FUNC(f)(f == 1 || f == 2&& number == 0?0:number)




我不知道OP是否取代了之前的帖子,但根据我能看到的
,测试应该是数字== 1,而不是0.


-

Christopher Benson-Manica |我*应该*知道我在说什么 - 如果我

ataru(at)cyberspace.org |不,我需要知道。火焰欢迎。


Hi guys,

I have a piece of code:

int func(int flag)
{
int number=1;
if (flag == 1)
return 0;
if(flag == 2)
if( number == 1)
return 0;
else
return number;
return(number);
}

I want to replace this function with a macro.

int main(void)
{
int result;
int flag = 0;
result = func(flag);
}

I tried using nested conditional operator convert the function to
macro, but end
up with some problems.

Can anybody please help me on this ??

thanks in advance for your help ....

解决方案

ju**********@yahoo.co.in wrote:

I have a piece of code:

int func(int flag)
{
int number=1;
if (flag == 1)
return 0;
if(flag == 2)
if( number == 1)
return 0;
else
return number;
return(number);
}
/Really/ this code? Because the test for `number == 0` seems
a little superfluous.
I want to replace this function with a macro.
Why?
int main(void)
{
int result;
int flag = 0;
result = func(flag);
}

I tried using nested conditional operator convert the function to
macro, but end
up with some problems.

Can anybody please help me on this ??



You haven''t shown us the code you had problems with, and you
haven''t said what the problems were, so it''s a bit tricky.

Remember that a conditional expression is an /expression/ and
hence <fx:sob/> can''t include declarations.

--
Chris "seeker" Dollin
"Reaching out for mirrors hidden in the web." - Renaissance, /Running Hard/


ju**********@yahoo.co.in wrote:


Hi guys,

I have a piece of code:

int func(int flag)
{
int number=1;
if (flag == 1)
return 0;
if(flag == 2)
if( number == 1)
return 0;
else
return number;
return(number);
}

I want to replace this function with a macro.

int main(void)
{
int result;
int flag = 0;
result = func(flag);
}

I tried using nested conditional operator convert the function to
macro, but end
up with some problems.

Can anybody please help me on this ??



#define FUNC(f) (f == 1 || f == 2 && number == 0 ? 0 : number)

--
pete


pete <pf*****@mindspring.com> wrote:

if(flag == 2)
if( number == 1)
return 0;

#define FUNC(f) (f == 1 || f == 2 && number == 0 ? 0 : number)



I don''t know if OP superseded a previous post, but based on what I can
see, the test should be number == 1, not 0.

--
Christopher Benson-Manica | I *should* know what I''m talking about - if I
ataru(at)cyberspace.org | don''t, I need to know. Flames welcome.


这篇关于嵌套条件运算符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆