When is a statement an expression?
Sho Kuwamoto
sho at pur-phy
Fri Apr 28 08:17:01 AEST 1989
In article <1043 at itivax.iti.org> scs at vax3.iti.org (Steve Simmons) writes:
<
<A friend was over tonight and we were talking over wierd C code
<we have written. [...]
<
<main()
<{
< int a = 0 ;
<
< a = if ( a == 1 )
< 12 ;
< else
< 14 ;
< printf( "Value of a is %d\n", a ) ;
<}
Perhaps someone else can explain this more technically, but it seems
to me that...
1) "if" is a branching operation. It cannot be assigned to an lvalue.
2) "12;" cannot be executed. It is not a legal expression.
This, however, should work:
a = (a==1)?12:14;
-Sho
More information about the Comp.lang.c
mailing list