## Jboy05

Consider the following user-defined function:

``````void Quick_Change (int x, int & y)
{
if (x == 0)
y = 10;
else if (y == 0)
x = 10;
}``````

Assume the values in variable A and B are both of int type. How do I find what the values are after execution of the statement Quick_Change(A,B), if the values of A and B are

0 and 5 respectively?
5 and 0 respectively?
5 and 5 respectively?
0 and 0 respectively?

## Dave Sinkula 2,398

Assuming you mean without using a program, perhaps using pencil and paper to solve each case? The first parameter is passed by value, so it will remain unchanged in the calling function after the function call; the second parameter is passed by reference, so its value may be changed in the calling function following the function call.

either way

## codeaa 3

Maybe this is a little better:

## Jboy05

what does the "==" mean?

## Jboy05

nvm it means equal to

## Dave Sinkula 2,398

The `==` operator compares for equality.

yea

## Jboy05

Tell me if this is right

0 and 5 respectively? A=0, B=10

5 and 0 respectively? A=10, B=0

5 and 5 respectively? A=5, B=5

0 and 0 respectively? A=10, B=10

## codeaa 3

Two of them are wrong.

You need to learn by-reference and by-value parameters.

## Jboy05

really which two?

## codeaa 3

You have 1 and 3 right.

I'll give you a quick explanation.

You have two parameter types to your function: by-value and by-reference.

int x is by-value.
int &y is by-reference.

What this basically means is any change made to x within that function is local to that function. It will not change the of the variable A used to call the function.

By-reference means that any change to y within that function will also change the value of the variable B used to call that function.

## Jboy05

0 and 5 respectively? A=0, B=10

5 and 0 respectively? A=5, B=0

5 and 5 respectively? A=5, B=5

0 and 0 respectively? A=0, B=10

Looks right.

thanks !