Go Back   Velocity Reviews > Newsgroups > MCSD
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

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

 
Thread Tools Search this Thread
Old 06-29-2003, 01:53 PM   #1
Default Re: One code, 2 different results C# vs C++


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
>
> 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?
> >>
> >> Regards,
> >>
> >> Caio Proiete
> >> MCSD (Visual C++)
> >>

> >
> >+= takes priority over prefix decrement.
> >--
> >Thanks
> > DEK
> >.
> >





clyclopedic
  Reply With Quote
Old 06-29-2003, 02:41 PM   #2
Shailendra Sharma
 
Posts: n/a
Default Re: One code, 2 different results C# vs C++

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
>>
>> 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?
>> >>
>> >> Regards,
>> >>
>> >> Caio Proiete
>> >> MCSD (Visual C++)
>> >>
>> >
>> >+= takes priority over prefix decrement.
>> >--
>> >Thanks
>> > DEK
>> >.
>> >

>
>
>.
>

  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump