Forums Register Login

evaluation of expression

+Pie Number of slices to send: Send
Hi,
How to evaluate the following expression


Can any one of u tell me, which operators are left associative and which operators are right associative?

Thanx in advance
+Pie Number of slices to send: Send
Hi there,
After the execution of this expression b1 will have value
FALSE as this expression consists of subexpressions, and therefore
first of all subexpressions will be evaluated
in given question
boolean b1 = false?false:true?false:true?false:true;
it will break to
boolean b1 = (false?false true?false true?false:true)));
and result is accordingly...........
+Pie Number of slices to send: Send
It ultimately boils down from the rightmost to the left. The subexpressions get executed and the results assigned and this continues in a chain from right to left.
+Pie Number of slices to send: Send
I think this is one of those
"think-like-a-compiler" kinda question.

lets see how we can evaluate this expression.
move from left to right as per associativity rules.

step 1: input--> false?false:true?false:true?false:true;
output--> false?false true?false:true?false:true);

step 2: input--> false?false true?false:true?false:true);
output--> false?false true?false true?false:true));

step 3: input--> false?false true?false true?false:true));
output--> false?false true?false true?false true)));

brackets shud clear your doubt a little bit....
does it??

-Narender
"Rock Steady"
+Pie Number of slices to send: Send
oh nooooooooo....
i didnt not put soooo many sad emoticons in my message.

+Pie Number of slices to send: Send
i am not gonna give up this easy.


step 1: input--> false?false:true?false:true?false:true;
output--> false?false: (true?false:true?false:true);

step 2: input--> false?false: (true?false:true?false:true);
output--> false?false: (true?false: (true?false:true));

step 3: input--> false?false: (true?false: (true?false:true));
output--> false?false: (true?false: (true?false true)));
Everybody's invited. Even this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 734 times.
Similar Threads
left associative or right associative ?
Summarization required
Conditional Operator doubt?
conditional expression chaining
group conditional operators
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 05:16:50.