If you pass by value, you copy the variable in the method. This means that any changes made to this variable do not match the original variable. This means that your result will be as follows:
2 1 1 3 2 5
If you followed a link that passes the address of your variable (instead of creating a copy), then your result will be different and will reflect the calculations performed in swap (int a, int b). Did you run this to check the results?
EDIT After some research, I found a few things. C ++ Does not support Pass-by-value-result, however it can be modeled. To do this, you create a copy of the variables, pass them by reference to your function, and then set the initial values ββto temporary values. See code below ..
#include <iostream>
This will give you the results:
1 2 3 2 2 1
This type of transfer is also called Copy-In, Copy-Out. Fortran uses it. But thatβs all I found during my searches. Hope this helps.
source share