Question
There are several parts to this question which are to be answered independently and separately. Each part consists of a fragment of C/C++ code. Write
There are several parts to this question which are to be answered independently and separately. Each part consists of a fragment of C/C++ code. Write the exact output produced by the code in the answer box. If an error occurs, or it enters an infinite loop, state and explain why.
You may show workings outside the answer box in the space beside it. Partial marks may be awarded for workings if the final answer is wrong. Assume that all appropriate preprocessor directives e.g., #include , etc. have already been defined.
A.
int f(int &x) {
x *= 2;
cout << "f:" << x << endl;
return x;
}
int g(int x) {
cout << "g:" << x << endl;
return f(x) + x;
}
int main() {
int x = 2;
int y = g(f(x));
cout << x << "," << y << endl;
}
B.
int i;
for (i = 0; i < 10; ++i) {
cout << i << ",";
if (i % 2) { ++i; }
if (i % 3) { continue; }
if (i % 5) { break; }
}
cout << i << endl;
C.
int date = 30/9/2021;
if (date) {
cout << "today" << endl;
} else {
cout << "is" << endl;
}
date += 1;
if (date == 1/10/2021) {
cout << "childrens" << endl;
} else if (date+2 == 31/10) {
cout << "day" << endl;
}
cout << date << endl;
Step by Step Solution
3.42 Rating (155 Votes )
There are 3 Steps involved in it
Step: 1
A cpp int fint x x 2 cout f x endl return x int gint x cout g x endl return fx x int main int x 2 in...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started