Report a bug
If you spot a problem with this page, click here to create a Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using a local clone.

Function Parameters Solutions

Function Parameters Dersi Problem Çözümleri

Because the parameters of this function are the kind that gets copied from the arguments, what gets swapped in the function are those copies.

To make the function swap the arguments, both of the parameters must be passed by reference:

void swap(ref int first, ref int second) {
    const int temp = first;
    first = second;
    second = temp;
}

With that change, now the variables in main() would be swapped:

2 1

Although not related to the original problem, also note that temp is specified as const as it is not changed in the function.