Hey there was a function in my text which read like this;

Suppose this is the input

a=5, b=10, c=15

void find(int a, int& b, int& c)

{

int temp;

c= a+b;

temp=a;

a=b;

b=2*temp;

}

I want to know why I find this function so confusing.

So I understand c= a+b

temp= a

but a=b

then b= 2* temp;

I don't get this what happens when it says a =b ? Does this assign a the value of 10.

But if it does then does the next line have b as 10 so it would be 10 = 2*temp?

Or is it just b= 2*5 where 5 is just the value of a.

So as you can read I'M CONFUSED! HELP ha.

Thanks a lot.

Suppose this is the input

a=5, b=10, c=15

void find(int a, int& b, int& c)

{

int temp;

c= a+b;

temp=a;

a=b;

b=2*temp;

}

I want to know why I find this function so confusing.

So I understand c= a+b

temp= a

but a=b

then b= 2* temp;

I don't get this what happens when it says a =b ? Does this assign a the value of 10.

But if it does then does the next line have b as 10 so it would be 10 = 2*temp?

Or is it just b= 2*5 where 5 is just the value of a.

So as you can read I'M CONFUSED! HELP ha.

Thanks a lot.

`temp`

becomes equal to the value `a`

had when the assignment was executed, so 10A case like the second you described can happen if

`temp`

was a pointer or a reference. You'll learn about those with time
Call that function with different numbers and you'll have a better idea about whats going on.

But the = sign is an assignment operator, for example:

a gets assigned the sum of b and c, the value of a before that line doesn't matter in the slightest.

But the = sign is an assignment operator, for example:

`a = b + c;`

a gets assigned the sum of b and c, the value of a before that line doesn't matter in the slightest.

Topic archived. No new replies allowed.