0
void increment(int a)
{
    a+=2
}

void assign(int a)
{
    a=a+2
}

In which of the parameter passing technique a call to increment(b) will have a different effect from a call to assign(b)

1) call by value 2) call by value result 3) call by reference 4) call by name

2 Answers2

0

The first is one operation ie store value a+2 in a (+=) The second is two operations ie calculate value a+2 (+) and assign to a (=)

It is very dependent on language though how these are implemented.

adamfowlerphoto
  • 2,708
  • 1
  • 11
  • 24
  • okay, can you say In which of the following parameter passing technique a call to increment(b) will have a different effect from a call to assign(b) and why ? 1) call by value 2) call by value result 3) call by reference 4) call by name – Amrata Ramchandani Oct 30 '17 at 16:36
  • The final result will be the same regardless. Just one of them (+=) in some cases could be more optimal – adamfowlerphoto Oct 30 '17 at 17:19
0

In most cases (assuming x += y is equivalent to x = x + y), no difference. Also, in most languages both functions will not affect the value passed to it, so these are doing nothing.

Andrey Belykh
  • 2,578
  • 4
  • 32
  • 46