comp.lang.c
[Top] [All Lists]

Re: ?: as an lvalue

Subject: Re: ?: as an lvalue
From: Dave Hansen
Date: Mon, 31 Mar 2008 11:27:47 -0700 PDT
Newsgroups: comp.lang.c

On Mar 30, 7:19 am, Richard Heathfield <r...@xxxxxxxxxxxxxxx> wrote:
> Rahul said:
>
> > Hi Everyone,
>
> >  I have the following piece of code, and i expected an error, however
> > i don't get an error,
>
> > int main()
> > {
> > int aa=0,b=0;
> > 1>0?aa:b = 10;
>
> This is a syntax error (which therefore requires the implementation to
> diagnose it as such). The syntax of the conditional operator is:
>

I believe the syntax is legal.  It just doesn't do what the OP wanted
it to.

Consider that it parses as

   (1>0)?(aa):(b=10);

Change it to 1<0?aa:b=10; and see the result...

Regards,

   -=Dave

<Prev in Thread] Current Thread [Next in Thread>
Privacy Policy