Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C Moderated > strange operato...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 11 Topic 919 of 1142
Post > Topic >>

strange operator problem

by "dreamume" <dreamume@[EMAIL PROTECTED] > Mar 29, 2007 at 01:23 AM

Hi, everyone!
Here is my simple test code:

int main()
{
    int b = 3, c = 5;
    int a = ( 1 == 1 || b > c ? b : c );    // sentence 1

    printf( "%d\n", a );
}

I thought the result should be 1, but is 3, if I change the sentence 1
like this,
int a = ( 1 == 0 || b > c ? b : c );   // the result is 5
or int a = ( 1 == 1 || ( b > c ? b : c ) );   // the result is 1

But I can't explain why, I guess it's a operator precedence level
problem.
Who can help me?
-- 
comp.lang.c.moderated - moderation address: clcm@[EMAIL PROTECTED]
 -- you must
have an appropriate newsgroups line in your header for your mail to be
seen,
or the newsgroup name in square brackets in the subject line.  Sorry.
 




 11 Posts in Topic:
strange operator problem
"dreamume" <  2007-03-29 01:23:58 
Re: strange operator problem
Barry Schwarz <schwarz  2007-04-16 15:16:22 
Re: strange operator problem
Martin Vuille <jpmv27@  2007-04-16 15:16:48 
Re: strange operator problem
Steve Bickerton <bick@  2007-04-16 15:17:23 
Re: strange operator problem
=?UTF-8?B?SGFucy1CZXJuaGF  2007-04-16 15:17:51 
Re: strange operator problem
jgd@[EMAIL PROTECTED] (J  2007-04-16 15:18:08 
Re: strange operator problem
"Jonas" <spa  2007-04-16 15:18:38 
Re: strange operator problem
Thomas Richter <thor@[  2007-04-16 15:18:15 
Re: strange operator problem
"Siddhartha Gandhi&q  2007-04-16 15:19:04 
Re: strange operator problem
"seni.yin" <  2007-04-16 15:19:05 
Re: strange operator problem
"=?gb2312?B?uq3X0yhI  2007-04-16 15:19:09 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Wed Aug 27 17:47:42 CDT 2008.