Please answer and explain why you pick this answer(utilize C++ logic) 1. A funct
ID: 3626418 • Letter: P
Question
Please answer and explain why you pick this answer(utilize C++ logic)1. A function can be defined within the definition of another function.
a. TRUE b. FALSE
Use the following function definition for the next 2 questions
void f1( int n1, int &n2 )
{
n1 = n1 + 1;
n2 = n2 + 2;
}
2. What is output by the following main function?
int a = 10;
int b = 20;
f1(a, b);
cout << a << “ “ << b << endl;
a. 10 20 b. 11 22 c. 11 20 d. 10 22
3. What is output by the following main function?
int a = 10;
int b = 20;
f1(a, b);
f1(b, a);
cout << a << “ “ << b << endl;
a. 10 20 c. 12 22 e. 12 20
b. 13 23 d. 10 22 f. 12 21
Use the following code for the next 3 questions
int main( )
{
int x = 3;
int i = 0;
while ( i < x )
{
int y = 5;
++i;
y += 2;
}
cout << i << " ";
cout << y << endl;
return 0;
}
4. Which statement in the code above has a syntax error?
a. int y = 5; d. cout << y << endl;
b. y += 2; e. ++i;
f. None of the above
c. cout << i << " ";
5. In terms of scope, the variable i in the above code is a ______________________.
a. local variable c. global constant
b. global variable d. function parameter variable
Explanation / Answer
1. False, you can't define a function inside a function. 2. d. 10 22. See the call trace: f(10, 20) // b becomes 22, a stays the same since there's no reference passed. print 10 22 3. c. 12 22 after f(10, 20), we have f (22, 10), so b = 22 and a = 12, so output is 12 22. 4. d, because "int y" does not exist outside the while loop, so it won't print. 5. a, since it is local to the main method.
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.