Assume the following two functions have been declared: int f(int& x, int y) { X
ID: 3559953 • Letter: A
Question
Assume the following two functions have been declared: int f(int& x, int y) { X += 2; return x + y; int g(int x, int y, int z) { z = X * Yi return x + y + z; If in the main program all the following variables are defined as ints, what output does the fol-4>wing code in the main program produce? , '}- ) V A. [2] a = 1; b = 2 ; c = 4; , ._ '"]. I x = f (a, b); ) y = g(a, b, c); cout << x <""= endl; 1 v l cout << y << endl; cout << a << b << c << endl; B. [2] Assume that int& x in the definition for function f is replaced with int x. What output will the code from 4A above produce now?
Explanation / Answer
#include <iostream>
using namespace std;
int f(int& x, int y) { x+= 2; return x + y; }
int g(int x, int y, int z) { z = x * y; return x + y + z;}
int main() {
int a = 1,b=2,c =4;
int x = f(a,b);
int y = g(a,b,c);
cout << "x="<<x <<endl;
cout<<"y="<<y<<endl;
cout <<"a="<<a<<" "<<"b="<<b<<" "<<"c="<<c<<endl;
return 0;
}
/*output*/
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.