|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
|
#2
|
|||
|
|||
|
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. |
![]() |
| Viewing: Web Development Archives > FAQs > C/C++ > A question about swap |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|