What is the output of the following code value of a and valu
What is the output of the following code (value of a and value of b)? void func1(int * p1, int*p2) {int temp; temp = * p1; *p1 = *p2; *p2 = temp;} int main() {int a = 10, b = 20; func1(&a;, &b;); cout
Solution
c)answer:-
output is:
value of a is20
value of b is10
explanation: -
call by reference method is used here...
both variable are swapped in the func1() function, we have passed the reference of current variables, so, they are swapped
d)answer:-
output is:
404141
explanation:-
two pointer variables are created ptr1,ptr2..
both are assigned to a same memory block..
40 value is assigned to *ptr1, means it also assigned to *ptr2
both values of *ptr1 and *ptr2 is 40
ptr1 is printed, means 40 is printed
(*ptr2)++, now *ptr2 is incremented, so its value is now 41, and ptr1 value also 41
now *ptr1,*ptr2 are printed, means 4141 is printed
the output is:
404141
