I tried to debug this function in Visual Studio Express 2004
http://paste.ofcode.org/EnJsc5iJ7BFmPBCP7Tg86Y
I would like to understand how it works. Maybe I already found it, hut there is not something clear during the debuging in VS.
Here are the notes that I added to the code:
1 2 3 4 5 6
|
while ((*a != '\0') && (*b != '\0'))
{
temp = *a; // 1) set first character of variable "a" to temp
*a++ = *b; // 2) set first character of variable "a" to first character of variable "b" and then increase array pointer +1
*b++ = temp; // 3) set b to temp and then increase array pointer +1
}
|
Original state: a="world", b="hello ",*a="w",*b="h"
I added breakpoint to while loop and then I debugged it line by line. I thought I should see the a or b how it changes to a="horld", b="wello" but it erases characters from the string (this is how it looks to me). So it looks like so: a="orld", b="ello " (watching a and watching b).
Now watching *a and *b: *a="o", *b="e".
Do you have idea why I cannot see the complete string in the time how it is changed? I see only the result on the cout line.