Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Computer Certification > MCSD > One code, 2 different results C# vs C++

Reply
Thread Tools

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

 
 
Shailendra Sharma
Guest
Posts: n/a
 
      06-29-2003
The difference lies in handling of extended assignment
operators such as +=, -=, /= etc etc in different
languages such as Java or C# versus C++.
In Java it is handled like this...
<variable><op>=<expression> the symantics for this are
<variable> = (<type>)(<variable><op>(<expression>))
Note, in Java the <variable> is evaluated just once upon
entry v/s C++ where the latest values for the variable is
used, hence the difference. Please refer to "Programmers
Guide to Java Certification by Khalid Mughal, page 53" for
reading up on Java's handling of Extended Assignment
operators. I do not think it is operator precedence.
Extended assignment operators have same precedence as
assignment operators which is the lowest in the precedence
table, --, ++ are ranked much much higher than assigment
operators....


>-----Original Message-----
>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++)
>.
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Different tuples to one container? (One type of a pointer to point to different kinds of tuples?) fff_afafaf@yahoo.com C++ 5 10-05-2006 11:17 PM
RE: hash() yields different results for different platforms Kerry, Richard Python 2 07-13-2006 01:16 PM
hash() yields different results for different platforms Qiangning Hong Python 12 07-12-2006 02:08 PM
Prefix increment/decrement results in lvalue, but postfix one results in rvalue? lovecreatesbeauty C++ 8 09-12-2005 10:23 PM
Different defrag utilities, different results! cygnian@msn.com Computer Support 6 05-12-2005 06:25 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57