Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 5th, 2006, 01:05 PM
Registered User
 
Join Date: Jun 2006
Location: , , .
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default Problem to Swap two number in C#

I have try the following code in Turbo C it works fine.
but when i try the same in C# it not give me a proper result.i dont know why it so

Turbo C
================================================== ===================
#include<stdio.h>
void main()
{
       int a,b;
       a=10;
       b=20;
       //Before swap two numbers
       printf("a = %d\n",a);
       printf("b = %d\n",b);

       //After swap two numbers
       a^=b^=a^=b;
       printf("a = %d\n",a);
       printf("b = %d\n",b);
}
Output
a = 10
b = 20
a = 20
b = 10

C#
================================================== ===================
using System;
class myclass
{
        public static void Main()
        {
                int a,b;
                a=10;
                b=20;
                //Before swap two numbers
                Console.WriteLine("a = {0}",a);
                Console.WriteLine("b = {0}",b);

                //After swap two numbers
                a^=b^=a^=b;
                Console.WriteLine("a = {0}",a);
                Console.WriteLine("b = {0}",b);
        }

}
Output
a = 10
b = 20
a = 0
b = 10

if any one know then help me to understand why the output is differ in c and c#.
Reply With Quote
  #2 (permalink)  
Old June 5th, 2006, 05:12 PM
Authorized User
 
Join Date: Dec 2005
Location: San Nicolas, Buenos Aires, Argentina.
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to arielote Send a message via MSN to arielote Send a message via Yahoo to arielote
Default

Friend:

For me the result is OK, because the expresion a^=b^=a^=b, could be analized like:

a^=b (Call it Z)

a^=b^=a^=b may be read as ((a^=b) ^= (a^=b)), equates Z ^= Z equates 0.

Regards


Ariel


---
Ariel Folonier
San Nicolas
Argentina
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to swap the table column value shahidmca SQL Language 2 July 31st, 2007 06:43 PM
Swap Images Mike707 Dreamweaver (all versions) 3 December 18th, 2006 01:05 PM
swap image onclick The Beginner Javascript How-To 2 November 8th, 2006 08:42 AM
How to Swap two integers without temp variable ramk_1978 C# 2 February 28th, 2006 08:03 PM
How to swap many html files to same <i frame> bekim Javascript How-To 9 January 21st, 2005 11:13 PM



All times are GMT -4. The time now is 10:35 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.