0 votes 0 votes void f(int x,int &y,const int &z) {x+=z; y+=z; } int main() { int a=22,b=33,c=44; f(a,b,c); f(2*a-3,b,c); printf("a=%d b=%d c=%d",a,b,c); return 0; } Programming in C programming-in-c + – Nishi Agarwal asked Mar 10, 2019 Nishi Agarwal 614 views answer comment Share Follow See 1 comment See all 1 1 comment reply Bhaskar Singh commented Mar 10, 2019 reply Follow Share This code must through an error 0 votes 0 votes Please log in or register to add a comment.
1 votes 1 votes Note:-func(int &a) means it'll receive the address of the argument being passed when the function is invoked with func(int x) in some caller module(main() function in this case).In other words it is call by reference and any change of "a" inside func() will reflect in the caller module. Now,initially:-a=22,b=33,c=44(given in the snippet),we need to worry about value of "b" & "c" only,as second and third parameters of the function signature are as highlighted "void f(int x,int &y,const int &z)" and the function is called as "f(int a,int b, int c)".Now as 3rd argument is treated as constant and it's never updated in "f()" we don't need to worry about "c" also,and it'll remain constant throughout.Only "b" will be modified as "y" is updated in "f" function as follows:- Dry run table a b c Intially 22 33 44 After f(a,b,c) 22 (33+44)=77 44 After f(2*a -3,b,c) 22 (77+44)=121 44 So,a=22,b=121,c=44 is the final output Shinei Nouzen answered Mar 10, 2019 • edited Mar 10, 2019 by Shinei Nouzen Shinei Nouzen comment Share Follow See 1 comment See all 1 1 comment reply venkatesh pagadala commented Mar 10, 2019 reply Follow Share $77+44=121 $ So answer is 22, 121, 44 1 votes 1 votes Please log in or register to add a comment.