Question: Problem 4 Consider the following program: #include using namespace std; int f ( int a, int &b, char &c) { 1. int result; 2. if
Problem 4
Consider the following program:
#include
using namespace std;
int f ( int a, int &b, char &c) {
1. int result;
2. if (c == a) {
3. a = a+(++b);
4. result = b;
5. } else if (c == s) {
6. b = b*(a++);
7. result = a - b;
8. } else {
9. c = ?;
10. result = --b;
11. }
12. return result;
}
void main() {
13. int x = 2, y = 4, z;
14. char ca = a;
15. z = f(x, y, ca);
16. cout << x = << x, y = << y << z = << z << ca = << ca << endl;
17 ca = s;
18. {
19. int x=3, z = -2;
20. x = calc (z, y, ca);
21. cout << x = << x, y = << y << z = << z << ca = <
22. }
23. cout << x = << x, y = << y << z = << z << ca = << ca << endl;
24. ca = a;
25. z = calc(x, y, ca);
26. cout << x = << x, y = << y << z = << z << ca = << ca << endl;
27. ca = d;
28. x = calc (x, z, ca);
29. cout << x = << x, y = << y << z = << z << ca = << ca << endl;
}
1. What are the input and output parameters to the function f?
2. Trace the program above, by showing the sequence of lines to be executed and the result of executing those specific lines. Please provide explanation of your tracing of the code per line in // form.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
