1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Can some one answer this question

Discussion in 'C' started by avinash_reddy, Apr 10, 2008.

  1. avinash_reddy

    avinash_reddy New Member

    Joined:
    Apr 10, 2008
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    hi friends can some one answer this question plz

    int x=2;
    int r= x-- * ++x + ++x;
    printf("x= %d, r= %d", x, r);

    and also for

    r= ++x + ++x * --x;

    and

    r= ++x + ++x * x--;

    can some explain how these expressions are eveluated
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,285
    Likes Received:
    364
    Trophy Points:
    83
    The answer can change from compilers to compilers and so see what is the output in your compiler and just try justifying it.
     
  3. tarek issa

    tarek issa New Member

    Joined:
    Apr 10, 2008
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    i understood ur question.
    there is a trick in doing x++ and ++x, for example:
    if doing this:
    ++x*2 first x multiplyese by 2, and then it (x) increases by 1.
    if doing this:
    x++*2 first x increases by 1, and then the multiply will be done.
     
  4. technosavvy

    technosavvy New Member

    Joined:
    Jan 2, 2008
    Messages:
    52
    Likes Received:
    0
    Trophy Points:
    0
    trying googling sequence point and u will understand why it is an undefined behaviour
     

Share This Page