Given the function definition void something ( int a, int& b ) { int c; c = a + 2; a = a* 3; b = c + a; } what is the output of the following code fragment that invokes something? (All variables are of type int.) r = 1; s = 2; t = 3; something(t, s); cout << r << ' ' << s << ' ' << t << endl;

Respuesta :

Answer:

1 14 3

Explanation:

If that code fragment is put under a main() function and then it will yield the above output. According to the function something(), only changes in value second parameter will be reflected and first will be unchanged because second is passed by reference and the first one is passed as value so only address of 's' is passed, so, only its value is changed and the rest are same.

ACCESS MORE
EDU ACCESS
Universidad de Mexico