Computer Science, asked by rathi07, 10 months ago

can anyone explain how the answer comes​

Attachments:

Answers

Answered by sswaraj04
1

Answer:

Explanation:

int &x means passing by address

if we write int x then value is passed only

passing value means just what value of passing variable is passed to function but changes in new variable don't change original variable.

But here g is passed to x with address that means any change in x will change value stored in that address and that will also change g

:: is scope resolution operator

It denotes global variable here i.e int g=20

Now coming back to program

func(g,::g) ->g=7 is passed with address and global variable g=20 value is just passed.

x=x-y -> x=7-20=-13

now,x changed g changed -> g=-13

y=x*10 -> y=-13*10 =-130

first cout<<x<<","<<y..... returns  -> -13 , -130

second cout<<g<<","<<::g.... returns -> -13, 20

now again passing value

func(::g,g) -> g=20 is passed with address and g=-13(new value) is passed with value

x=x-y -> x=20-(-13) =33

now x changed, global variable g also changed from 20 to 33

y=x*10 -> y=33*10=330

third cout<<x<<","<<y..... returns -> 33,330

fourth cout<<g<<","<<::g.... returns ->-13, 33

And regarding output on last line It should be -13,33 not 33,-13

You can compile and check ; it's wrong surely

Hope it helps :-)

Mark me brainliest

Similar questions