prev up next   top/contents search

comp.lang.c FAQ list · Question 3.16

Q: I have a complicated expression which I have to assign to one of two variables, depending on a condition. Can I use code like this?

	((condition) ? a : b) = complicated_expression;


A: No. The ?: operator, like most operators, yields a value, and you can't assign to a value. (In other words, ?: does not yield an lvalue.) If you really want to, you can try something like

	*((condition) ? &a : &b) = complicated_expression;
although this is admittedly not as pretty.

References: ISO Sec. 6.3.15
H&S Sec. 7.1 pp. 179-180


prev up next   contents search
about this FAQ list   about eskimo   search   feedback   copyright

Hosted by Eskimo North