Re: One code, 2 different results C# vs C++

Discussion in 'MCSD' started by clyclopedic, Jun 29, 2003.

  1. clyclopedic

    clyclopedic Guest

    It is clearly not the case that assignment operators have higher precedence
    than prefix decrement in any of the languages in question.

    "Caio Proiete" <> wrote in message
    news:050d01c33cb2$669609a0$...
    > Well... maybe you're right...
    >
    > So the expression:
    > x += --x
    >
    > Would be
    > x = --(x + x)
    >
    > nice... but weird :p
    >
    > Thanks
    >
    > Caio Proiete
    > MCSD (Visual C++)
    >
    >
    > >-----Original Message-----
    > >In article <084701c33c51$4451b990$>,
    > > says...
    > >> Hi, I was just studying for my 70-315 test and had one
    > >> surprise. Look at this code:
    > >>
    > >> int myFunc()
    > >> {
    > >> int x;
    > >> x = 42;
    > >> x++;
    > >> x += --x;
    > >> return x;
    > >> }
    > >>
    > >> What is the value returned from myFunc()?
    > >> As a C++ programmer I said: "84 of course".
    > >>
    > >> But when I compiled with C#, the function returns "85".
    > >> Just to confirm, I also compiled the same code with

    > Java
    > >> and returned 85 either.
    > >>
    > >> Well... can anyone explain this? :p
    > >>
    > >> Regards,
    > >>
    > >> Caio Proiete
    > >> MCSD (Visual C++)
    > >>

    > >
    > >+= takes priority over prefix decrement.
    > >--
    > >Thanks
    > > DEK
    > >.
    > >
     
    clyclopedic, Jun 29, 2003
    #1
    1. Advertising

  2. Absolutely Correct....

    >-----Original Message-----
    >It is clearly not the case that assignment operators have

    higher precedence
    >than prefix decrement in any of the languages in question.
    >
    >"Caio Proiete" <> wrote in message
    >news:050d01c33cb2$669609a0$...
    >> Well... maybe you're right...
    >>
    >> So the expression:
    >> x += --x
    >>
    >> Would be
    >> x = --(x + x)
    >>
    >> nice... but weird :p
    >>
    >> Thanks
    >>
    >> Caio Proiete
    >> MCSD (Visual C++)
    >>
    >>
    >> >-----Original Message-----
    >> >In article <084701c33c51$4451b990$>,
    >> > says...
    >> >> Hi, I was just studying for my 70-315 test and had

    one
    >> >> surprise. Look at this code:
    >> >>
    >> >> int myFunc()
    >> >> {
    >> >> int x;
    >> >> x = 42;
    >> >> x++;
    >> >> x += --x;
    >> >> return x;
    >> >> }
    >> >>
    >> >> What is the value returned from myFunc()?
    >> >> As a C++ programmer I said: "84 of course".
    >> >>
    >> >> But when I compiled with C#, the function

    returns "85".
    >> >> Just to confirm, I also compiled the same code with

    >> Java
    >> >> and returned 85 either.
    >> >>
    >> >> Well... can anyone explain this? :p
    >> >>
    >> >> Regards,
    >> >>
    >> >> Caio Proiete
    >> >> MCSD (Visual C++)
    >> >>
    >> >
    >> >+= takes priority over prefix decrement.
    >> >--
    >> >Thanks
    >> > DEK
    >> >.
    >> >

    >
    >
    >.
    >
     
    Shailendra Sharma, Jun 29, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    13
    Views:
    1,096
    Martin Bodenstedt
    Oct 31, 2005
  2. Shailendra Sharma

    One code, 2 different results C# vs C++

    Shailendra Sharma, Jun 29, 2003, in forum: MCSD
    Replies:
    0
    Views:
    1,818
    Shailendra Sharma
    Jun 29, 2003
  3. Replies:
    6
    Views:
    922
    petrolhead
    May 12, 2005
  4. Tuna Fish
    Replies:
    0
    Views:
    406
    Tuna Fish
    Nov 20, 2003
  5. RichA
    Replies:
    3
    Views:
    311
    PeterN
    Nov 29, 2011
Loading...

Share This Page