First of all, in C (not in C++), there are no references, and the parameter-passing mechanism is always by value.
In first case, you create a pointer
x
on stack and never use it, so the value of this pointer is discarded. It's less obvious with
a
and
b
. The values of these pointers (not objects referenced by them, but pointers) are copies on stack and modified. When you return to the caller, the modified values are discarded, because the stack frame is removed. After return to the called, these two pointers remain the same.
Did you want just to swap two objects? Then you would need to use pointers to pointers.
In second case, the function
strcat
returns a value, but you ignore the return. Please see:
http://www.cplusplus.com/reference/cstring/strcat/[
^].
You can get a warning recommending you to use
strcat_s
instead, as
strcat
is considered unsafe.
—SA