On entry to your main function the argv input buffer contains the following (where # represents null):-
0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7
.|/|c|a|t|e|n|a|t|e|#|C|a|m|p|b|e|l|l|#|R|i|t|c|h|i|e|#|
argv[1] points to C at index [11]
argv[2] points to R at index [20]
Recall that strcat concats the p2
string to the end of p1 string IN PLACE, it does not create a new string like
java would.
The strcat is executed before the printf (as its an argument its value is needed) . Thus it concats "Ritchie" to the position of the null at end of "Campbell" which therefore overwrites your input buffer, giving this:-
0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7
.|/|c|a|t|e|n|a|t|e|#|C|a|m|p|b|e|l|l|R|i|t|c|h|i|e|#|#|
argv[2] still points to index [20] so the string at argv[2] now says "itchie".