Yes/No


Ad

Advertisements

I

Ian Malone

Meenu said:
Are the two statements same:
a<=20?b=30:c=30;
(a<=20)?b=30:c=30;

Google "C++ operator precedence"


(yes, unless you have some funny #define going round)
 
M

Meenu

Ian said:
Google "C++ operator precedence"


(yes, unless you have some funny #define going round)

Even I thought so, but the answer mentioned is no, and I can't figure
out a reason
 
I

Ian Malone

I didn't get it...:(
pls elaborate

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);
 
Ad

Advertisements

S

Simon Morgan

Are the two statements same:
a<=20?b=30:c=30;
(a<=20)?b=30:c=30;

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?
 
M

Meenu

Simon said:
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?

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.
 
L

lawrence.jones

Ian Malone said:
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);

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
 
Ad

Advertisements

E

Eric Sosman

CBFalconer said:
I wouldn't even bother to read them. They are infested with blank
elidation.

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 ...)
 
C

CBFalconer

Eric said:
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 ...)

Yeah, it didn't look right. Would you settle for Pernod?
 
J

junky_fellow

Meenu said:
Are the two statements same:
a<=20?b=30:c=30;
(a<=20)?b=30:c=30;

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.
 
C

Chris Croughton

The word you seek is "elision." As in "The Elision Fields,"
where one forgets one's past lives -- Egad! I'm turning Buddhist.

elide: omit by elision [Concise OED]. And it was the Elysian Fields,
which were Greek ("The Isles of the Blest"); the Romans later moved
them into the underworld for the Grateful Dead (er, I mean the righteous
dead <g>).

Not to be confused with Harlan Ellison...
(Interesting thought: How can something be "infested with"
an absence? Maybe I'd understand better if I were infested
with an absinthe ...)

Absinthe makes the font grow harder...

(But being infested with an absence of blanks is an interesting idea. I
knew exactly what he meant, but the mental image is fascinating.
Probably worth a thesis for a doctorate in philosophy...)

Chris C
 
Ad

Advertisements

E

Eric Sosman

Chris said:
CBFalconer wrote:



The word you seek is "elision." As in "The Elision Fields,"
where one forgets one's past lives -- Egad! I'm turning Buddhist.


elide: omit by elision [Concise OED]. And it was the Elysian Fields,
which were Greek ("The Isles of the Blest"); the Romans later moved
them into the underworld for the Grateful Dead (er, I mean the righteous
dead <g>).

pun: the humorous use of a word in such a way as to suggest
different meanings or applications or of words having the same
or nearly the same sound but different meanings [Webster's
Seventh New Collegiate Dictionary]

elide: e told a taradiddle, e did!
 
Ad

Advertisements


Top