C++ More Functions Stuff Test #2
Variables declared inside main() cannot be accessed/used inside functions defined below the main() function. T or F
True
What is the last value printed by the following code? -------------------------------------------------------------------- using namespace std; double AddPayroll (double ); int main () { for (int i = 1; i < 5; i++) cout << AddPayroll( i*10 ) <<endl; return 0; } double AddPayroll(double pay) { static double total = 0; total += pay; return total; } ------------------------------------------------------------- Did you notice the static keyword? (1) 100.0 (2) 100 (3) 100.0000 (4) 100. (5) 100.00 (7) 100.000
(1) 100.0
What is the output of the following code? Your output must be exact! Enter "nothing" if it produces no output. ----------------------------------------------------------- int foo(); int main() { int x, a =0; cout << foo() << endl; x = a; return 0; } int foo() { int a,b,x; a = 10; b = 100; x = a*b; return x; }
1000
What number is output for the last value of B in the following code? Enter "nothing" if it produces no output. ------------------------------------------------------------- #include <iostream> using namespace std; void TestA (int &Y, int Z) { Y++; Z++; return; } void TestB (int Y, int& Z) { Y *= 2; Z *= 2; return; } void TestC (int &Y, int& Z) { Y++; Z++; return; } int main () { int A=5, B=7 TestA(A, B); cout<< "Line 1: " << A << ", " << B << endl; TestB(A, B); cout<< "Line 2: " << A << ", " << B << endl; TestC(A, B); cout<< "Line 3: " << A << ", " << B << endl; return 0; }
15
Which of the following are true for global variables? (Even though you are never supposed to use global variables!!!) (pick 4) (1) Group of answer choices (2) can only be used inside main() (3) cannot be of type string (4) retains their values after the program end (5) scan be used in all of the code that is after it in the program (6) can be initialized when it is declared (7) are declared outside of any function (8) can only be type int (9) are declared inside main() (10) are EVIL! You should never use them for this course, and it is unlikely that you should ever use them, ever.
2 4 5 10
What is the last number output by the following code? Enter "nothing" if it produces no output. --------------------------------------------------------- #include <iostream> using namespace std; const int NUM = 10; void food_on_table() { static int food = NUM; food--; cout << food << endl; return; } int main () { for (int i = 0; i < 5; i++) food_on_table(); return 0; ;
5
Actual parameters (arguments) and formal parameters should have the same name to avoid confusion. T or F
False
In pass by reference, a copy of the parameter value is passed into the function, and when the function returns the orginal value passed in is restored. T or F
False
Parameter names in the prototype must be the same as formal parameter names. T or F
False
Any parameter that passes in data to the called function and passes data back out to the calling funciton is a ______________ parameter.
reference