C/C++
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
Go Back   Web Development Archives FAQs C/C++

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Web Development Archives Sponsor:
  #1  
Old July 4th, 2008, 08:19 PM
Chad
Guest
Dev Archives Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
A question about swap

I hope this question doesn't appear twice. I tried posting it once,
however, I got a stupid 505 internal error on google. When this
happens, the post will either post 30 minutes later or won't post at
all.

Given

void swap(int *x, int *y)
{
int temp;

temp = *x;
*x = *y;
*y = temp;
}

How does having a temp variable allow for anything to safely swap with
itself? Say x = 10 and y = 10. What would happen in the absence of
temp?

Chad

Reply With Quote
  #2  
Old July 4th, 2008, 09:00 PM
Ian Collins
Guest
Dev Archives Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
A question about swap

Chad wrote:
I hope this question doesn't appear twice. I tried posting it once,
however, I got a stupid 505 internal error on google. When this
happens, the post will either post 30 minutes later or won't post at
all.
>

Given
>

void swap(int *x, int *y)
{
int temp;
>

temp = *x;
*x = *y;
*y = temp;
}
>

How does having a temp variable allow for anything to safely swap with
itself? Say x = 10 and y = 10. What would happen in the absence of
temp?
>

Try writing the function without it and see what you get.

--
Ian Collins.

Reply With Quote
Reply

Viewing: Web Development Archives FAQs C/C++ > A question about swap


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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 Off
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT