It all depends on
swap2
function definition. If, for instance, the
swap2
function is defined for destroying the Universe then the program would abruptly terminate.
The following
C
program
#include <stdio.h>
int main()
{
int x = 5, y = 10;
swap2(x, y);
printf("%d, %d\n", x, y);
swap2(x, y);
printf("%d, %d\n", x, y);
return 0;
}
Will always output
5, 10
5, 10
for any correct implementation of the swap2 function, since the swap2 prototype must be
void swap(int x, int b);
(actually you can use another type for return value).
In C++
programming language the scenario may change, defining, for instance,
swap2
this way
void swap2( int & a, int & b)
{
int t = a;
a = b;
b = t;
}
Could you guess the actual output?