Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Smith and Roberson Business Law

Authors: Richard A. Mann, Barry S. Roberts

15th Edition

1285141903, 1285141903, 9781285141909, 978-0538473637

More Books

Students also viewed these Programming questions

Question

Solve 1. dx dy + x 1-xy=xy.

Answered: 1 week ago

Question

What is a multivariate data set?

Answered: 1 week ago

Question

What are the qualities the character hides from themselves?

Answered: 1 week ago

Question

What would they find most embarrassing if people knew?

Answered: 1 week ago