Menu

On conditional expression. Please help!

J Chen
2011-03-07
2012-09-26
  • J Chen

    J Chen - 2011-03-07

    Hi,

    I might posted the same message to the wrong forun, so I c&p the
    message help to ask help. Sorry for the dup.

    I am using Dev-C++ Version 4.9.9.2.
    I am confused by the results from compiling the following two statements:

    (A) x = 0 ? 2+5 : x=y;
    (B) x = 1? 2+5 : x=y;

    The variables x and y are declared as int and initialized.
    For (A), there is no error message from compiling and executing.
    However, for (B), the compiler showed the error message:

    invalid lvalue in assignment.
    I figured out that the compiler located the error at "x=y". But I
    could not find any explanation for this.
    Can anyone help? Thanks in advance.

    --
    JC

     
  • Steve A

    Steve A - 2011-03-16

    I recommend that you post your question to an active forum:
    http://cboard.cprogramming.com/

     
  • DARC

    DARC - 2011-06-14

    (A) x = 0 ? 2+5 : x=y;
    (B) x = 1? 2+5 : x=y;

    Try (B) x=1? x=2+5 : x=y; // add x = 2 + 5

     

Log in to post a comment.