Meenu wrote:[color=blue]
>
> Ian Malone wrote:
>[color=green]
>>Ian Malone wrote:
>>
>>[color=darkred]
>>>Google "C++ operator precedence"
>>>[/color]
>>
>>Oops, wrong ng. Obviously that says 'c operator precedence'
>>[/color][/color]
[color=blue]
>
> I didn't get it...:(
> pls elaborate
>[/color]
Thought I was reading comp.lang.c++, not comp.lang.c.
Incidentally, since the ternary operator is meant to
return a value, the assignments need to be parenthesised,
since they have a lower priority (they are statements to
be evaluated). You need
a<=20?(b=30):(c =30);
On Fri, 22 Jul 2005 03:39:33 -0700, Meenu wrote:
[color=blue]
> Are the two statements same:
> a<=20?b=30:c=30 ;
> (a<=20)?b=30:c= 30;[/color]
How's the homework going? Obviously not very well if you still haven't
grasped basic operator precedence. May I suggest reading a book or
actually attending class?
Simon Morgan wrote:[color=blue]
> On Fri, 22 Jul 2005 03:39:33 -0700, Meenu wrote:
>[color=green]
> > Are the two statements same:
> > a<=20?b=30:c=30 ;
> > (a<=20)?b=30:c= 30;[/color]
>
> How's the homework going? Obviously not very well if you still haven't
> grasped basic operator precedence. May I suggest reading a book or
> actually attending class?[/color]
Well thanks,
my confusion was that since parentheses only make the condition part
easier to see, other than that, i don't feel there would be any change
in the output.
In article <1122028773.687 405.231770@g14g 2000cwa.googleg roups.com> "Meenu" <meenu_kg@yahoo .com> writes:[color=blue]
> Are the two statements same:
> a<=20?b=30:c=30 ;
> (a<=20)?b=30:c= 30;[/color]
The same in what way? Both should give an error message from the compiler.
--
dik t. winter, cwi, kruislaan 413, 1098 sj amsterdam, nederland, +31205924131
home: bovenover 215, 1025 jn amsterdam, nederland; http://www.cwi.nl/~dik/
Meenu wrote:[color=blue]
>
> Are the two statements same:
> a<=20?b=30:c=30 ;
> (a<=20)?b=30:c= 30;[/color]
I wouldn't even bother to read them. They are infested with blank
elidation.
--
Chuck F (cbfalconer@yah oo.com) (cbfalconer@wor ldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home .att.net> USE worldnet address!
Ian Malone <ibm21@cam.ac.u k> wrote:[color=blue]
>
> Incidentally, since the ternary operator is meant to
> return a value, the assignments need to be parenthesised,
> since they have a lower priority (they are statements to
> be evaluated). You need
> a<=20?(b=30):(c =30);[/color]
The ? and : act like parentheses, so you only need to parenthesize the
final assignment:
a <= 20 ? b = 30 : (c = 30);
-Larry Jones
Mom must've put my cape in the wrong drawer. -- Calvin
CBFalconer wrote:
[color=blue]
> Meenu wrote:
>[color=green]
>>Are the two statements same:
>>a<=20?b=30:c= 30;
>>(a<=20)?b=30: c=30;[/color]
>
>
> I wouldn't even bother to read them. They are infested with blank
> elidation.[/color]
The word you seek is "elision." As in "The Elision Fields,"
where one forgets one's past lives -- Egad! I'm turning Buddhist.
(Interesting thought: How can something be "infested with"
an absence? Maybe I'd understand better if I were infested
with an absinthe ...)
Eric Sosman wrote:[color=blue]
> CBFalconer wrote:[color=green]
>> Meenu wrote:
>>[color=darkred]
>>> Are the two statements same:
>>> a<=20?b=30:c=30 ;
>>> (a<=20)?b=30:c= 30;[/color]
>>
>> I wouldn't even bother to read them. They are infested with blank
>> elidation.[/color]
>
> The word you seek is "elision." As in "The Elision Fields,"
> where one forgets one's past lives -- Egad! I'm turning Buddhist.
>
> (Interesting thought: How can something be "infested with"
> an absence? Maybe I'd understand better if I were infested
> with an absinthe ...)[/color]
Yeah, it didn't look right. Would you settle for Pernod?
--
Chuck F (cbfalconer@yah oo.com) (cbfalconer@wor ldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home .att.net> USE worldnet address!
Meenu wrote:[color=blue]
> Are the two statements same:
> a<=20?b=30:c=30 ;
> (a<=20)?b=30:c= 30;[/color]
No. In fact both will generate compilation error.
Since precedence of conditional operator is higher than
assignement operator, the following statement
a<=20?b=30:c=30 ; will be interpreted like
(a<=20?b=30:c)= 30;
LHS is not an lvalue, so the error.
Same is the reason for second statement.
Now, if you enclose "c=30" in parenthesis, it would
be interpreted as:
(a<=20?b=30:(c= 30)); which would complile OK.
junky_fellow@ya hoo.co.in writes:[color=blue]
> Meenu wrote:[color=green]
>> Are the two statements same:
>> a<=20?b=30:c=30 ;
>> (a<=20)?b=30:c= 30;[/color]
>
> No. In fact both will generate compilation error.[/color]
Doesn't that make them equivalent?
--
Keith Thompson (The_Other_Keit h) kst-u@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Comment