I was reading in somewhere the ternary operator is *right associative*

Wladimir Araujo Tavares
*Federal University of Ceará

*




On Fri, Jun 24, 2011 at 1:13 AM, Vishal Thanki <vishaltha...@gmail.com>wrote:

> Okay, I found the problem i think,
>
> (x > 10) ? y++: x = 10 is evaluated as ((x > 10) ? y++: x) = 10
> which is wrong..
>
> (x > 10) ? y++: (x = 10) will work.
>
>
> On Fri, Jun 24, 2011 at 9:22 AM, Vishal Thanki <vishaltha...@gmail.com>
> wrote:
> > yes, i understand that.. but is there any limitation in ternary
> > operator that the 2nd expression (after ":")should not use assignment
> > operator?
> >
> >
> >
> > On Fri, Jun 24, 2011 at 9:21 AM, Wladimir Tavares <wladimir...@gmail.com>
> wrote:
> >> Try this:
> >> #include <stdio.h>
> >> #include <stdlib.h>
> >> int main(int argc, char *argv[])
> >> {
> >>        int x = atoi(argv[1]);
> >>        int y = 10;
> >>        x = (x > 10) ? y++: 10;
> >>        return x;
> >> }
> >> Wladimir Araujo Tavares
> >> Federal University of Ceará
> >>
> >>
> >>
> >>
> >>
> >>
> >> On Fri, Jun 24, 2011 at 12:40 AM, Vishal Thanki <vishaltha...@gmail.com
> >
> >> wrote:
> >>>
> >>> Hey all,
> >>>
> >>> I think I am missing something very basic in C, and which is troubling
> >>> me. Following code is not compiling for me, can anyone explain why?
> >>>
> >>> vishal@ubuntu:~/progs/c\ 09:07:01 AM >$ cat ternary.c
> >>> #include <stdio.h>
> >>> #include <stdlib.h>
> >>> int main(int argc, char *argv[])
> >>> {
> >>>        int x = atoi(argv[1]);
> >>>        int y = 10;
> >>>        (x > 10) ? y++: x = 10;
> >>>        return x;
> >>> }
> >>> vishal@ubuntu:~/progs/c\ 09:07:08 AM >$ gcc ternary.c
> >>> ternary.c: In function ‘main’:
> >>> ternary.c:7: error: lvalue required as left operand of assignment
> >>>
> >>>
> >>> Vishal
> >>>
> >>> --
> >>> You received this message because you are subscribed to the Google
> Groups
> >>> "Algorithm Geeks" group.
> >>> To post to this group, send email to algogeeks@googlegroups.com.
> >>> To unsubscribe from this group, send email to
> >>> algogeeks+unsubscr...@googlegroups.com.
> >>> For more options, visit this group at
> >>> http://groups.google.com/group/algogeeks?hl=en.
> >>>
> >>
> >> --
> >> You received this message because you are subscribed to the Google
> Groups
> >> "Algorithm Geeks" group.
> >> To post to this group, send email to algogeeks@googlegroups.com.
> >> To unsubscribe from this group, send email to
> >> algogeeks+unsubscr...@googlegroups.com.
> >> For more options, visit this group at
> >> http://groups.google.com/group/algogeeks?hl=en.
> >>
> >
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to