C quiz questions/answers?
Rob Wehrli
plug-devel@lists.PLUG.phoenix.az.us
Mon Nov 5 20:05:13 2001
Julian M Catchen wrote:
>
> Well, I had to add parentheses on the win32 machine I was using at work,
> but thought that it should still work under gcc. I guess it doesn't...
Kevin is correct. (Whether he "peeked" or not, who knows :)
Seriously, this is an "operator precedence" problem, as Kev points out.
The "better" that he mentions below is really the best for clarity but
no more "right" than the first "fix" he recommends in using the
parenthesis around the weaker assignment operator. Of course, in his
"better" approach, it isn't as easy to "fool" people on test questions
;0
> >
> > In order to make this work as desired, you'd have to write it as:
> >
> > i < 100 ? x = i : (x = 100);
> >
> > Or even better:
> >
> > x = i < 100 ? i : 100;
> >
> > Kevin
Take Care.
Rob!