|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Variable swapping question
Given something like the following
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? Like for example x = 10 and y = 10. What would happen in the absence of temp? Chad |
![]() |
| Viewing: Web Development Archives > FAQs > C/C++ > Variable swapping question |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|