They are c++ practice question from Cplusplus_for_Everyone_2nd_Edition. r5.4 Tru
ID: 3672852 • Letter: T
Question
They are c++ practice question from Cplusplus_for_Everyone_2nd_Edition.
r5.4 True or false?
a. A function has exactly one return statement.
b. A function has at least one return statement.
c. A function has at most one return value.
d. A function with return value void never has a return statement.
e. When executing a return statement, the function exits immediately.
f. A function with return value void must print a result.
g. A function without arguments always returns the same value.
r5.5 Consider these functions:
double f(double x) { return g(x) + sqrt(h(x)); }
double g(double x) { return 4 * h(x); }
double h(double x) { return x * x + k(x) - 1; }
double k(double x) { return 2 * (x + 1); }
Without actually compiling and running a program, determine the results of the
following function calls:
a. double x1 = f(2);
b. double x2 = g(h(2));
c. double x3 = k(g(2) + h(2));
d. double x4 = f(0) + f(1) + f(2);
e. double x5 = f(-1) + g(-1) + h(-1) + k(-1);
Explanation / Answer
Please find the answers below :
5.4)
a) false; in the case of if-else there will be more than one
b) false; not necessary, like in the case of void
c) fasle
d) false; void function also can return something like: return void(); return;
e) true;
f) false; not necessary
g) false
5.5)
a) x1=39
b) x2=400
c) x3=92
d) x4=62
e) x5=0
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.