01. What statements are true concerning positional binding for parameters? A. C/C++ use this form of formal to actual parameter binding. B. The 1st actual is bound to the 1st formal, the 2nd actual to the 2nd formal and so on. C. You cannot set default values for formal parameters in C++. D. The actual and the formal parameter names must match.
02. Why is this function call a compilation error in C#? Foo (out 5); // keyword 'out' specifies an out mode parameter A. a literal cannot be passed as an argument in C# B. 5 is not a modifiable L-value C. both A & B
03. What do you know about this error-free Perl code? &test(5, ' cats', 34); // will display "5 cats" on the screen. &test(' cats'); // will display "cats" on the screen. sub test { $first = $_[0]; $second = $_[1]; print "$first and $second\n"; } A. the implicit formal parameter in a subroutine is the array @_ B. the number of actual parameters in a subroutine call is dynamic C. both A & B
04. In C/C++, the default address binding for non-static variables that are local to a subroutine is A. heap dynamic B. stack dynamic C. implicit heap dynamic
05. Which of the following are primary design issues for procedures? A. what parameter passing mechanisms to provide B. whether to treat procedures as first-class objects C. whether or not to check parameter types D. whether variables local to the procedure are stack or heap dynamic
06. Which of the following are primary design issues for procedures? A. Can the number of parameters be dynamic? B. Can procedures be overloaded? C. Can procedures be generic? D. Can you have nested procedures?
07. What is true if a language does not support heap or stack dynamic address binding for variables local to a procedure (i.e., does not use a stack)? A. the languages cannot support recursion B. the binding of a local variable to an address is done by the compiler C. both A & B
08. In C++ pass by reference, the address of the actual parameter is the same as the address of the formal parameter.
09. If the address of the actual parameter is 0xffbefa28, and the address of the formal parameter is 0xffbefa0c, what do you know about the parameter passing mechanism? A. this is some version of pass by value B. if this is an in mode parameter, the R-value of the actual parameter is copied to the R-value of the formal parameter. C. both A and B are true
10. Which one of these mechanisms uses the same parameter passing semantics? A. Pass by value and pass by result B. Pass by value-result and pass by reference C. Pass by result and pass by reference
11. Which parameter passing mechanism supports one-way parameter passing only? A. pass by value B. pass by result C. both A and B
12. Which two languages support two-way parameter passing? A. Fortran B. C C. C++ D. Java
13. Below is a valid PHP function definition and call. From this you know what about PHP? function foo($var) { if ($var % 2 == 1) { print "odd"; return 3; } else { print "even"; return 23.7; } } foo("hello"); A. PHP does not enforce parameter type checking B. PHP does not enforce type checking on a return value C. both A & B
14. Select the true statement that describes how string arrays are passed in C. A. If the parameter is char[] the address of the array is passed by value. B. If the parameter is char[] the entire array is passed by value. C. If the parameter is char * the array is passed by reference.
15. In languages such as C/C++, where n-dimen arrays are treated like single dimensional arrays, the sizes of which dimensions must be included in the actual parameter? A. the size of every dimension must be included B. the size of every dimension but the first C. the size of every dimension but the last
16. What type of parameter passing mode has no side effects? A. in mode B. in out mode C. out mode
17. Accesses to static local variables are slightly more efficient than accesses to stack-dynamic local variables because a reference to a A. static local variable is a single address resolution. B. stack-dynamic variable is one address resolution added to an offset. C. both statements are true
The next questions refer to the referencing environment of sub2 in this JavaScript code. Assume that sub1() is called. function sub1(){ var x = 1; function sub2(){ alert(x); }; function sub3(){ var x = 2; sub4(sub2); }; function sub4(subx){ var x = 3; subx(); } sub3(); };
18. If '1' is displayed in the alert, the referencing environment of sub2 is A. the static (lexical) environment of the function definition. B. the dynamic environment during function execution. C. the static environment of sub2 as an actual argument.
19. If '2' is displayed in the alert, the referencing environment of sub2 is A. the static environment of the function definition. B. the dynamic environment of the function execution. C. the static environment of sub2 as an actual argument.
20. If '3' is displayed in the alert, the referencing environment of sub2 is A. the static environment of the function definition. B. the dynamic environment of the function execution. C. the static environment of sub2 as an actual argument.
21. Which of the following are design issues for procedures? A. What types of values can be returned? B. Are side effects allowed for some parameters and not for others? C. Are variable length parameter lists supported? D. Can parameters have default values?
22. A coroutine such as implemented in Python may multiple entry points but only one exit point.
23. Which statement are true? In all high-level languages a formal parameter A. may have a default value. B. is either a copy of or a reference to an actual parameter. C. name exists only within the scope of the procedure. D. name must match the actual parameter name.
24. The ability to store information in the call frame for each instance of a procedure call is essential for recursion. What often is stored in the call frame for function foo if foo is recursive? A. foo's local variables B. the return value of the next call to foo C. arguments passed to foo (formal parameters) D. actual parameters
25. All local non-static variables in a procedure are bound to a new storage location for each function call.
26. What is true about the in out mode mechanism of pass-by-reference in C++ ? A. Any change made to the formal parameter in the subroutine is made immediately to the actual parameter in the calling program. B. Any change made to the formal parameter in the subroutine is copied to the actual parameter in the calling program upon exit.
27. What is true about this C++ code (& denotes a pass-by-reference parameter)? void fun(Stuff& stuff) { stuff.setCount(200); // line #1 Stuff new_stuff(999); stuff = new_stuff; // line #2 new_stuff.setCount(222); } A. line #1 modifies the Stuff object in the caller B. line #2 doesn't modify anything in the caller C. both statements are true
28. Which is an example of parametric polymorphism? A. a template function in C++ B. a (void *) parameter in C C. both A & B
29. A default value for a subroutine parameter if supported must be attached to A. the actual parameter. B. the formal parameter.
30. This python function call test_function(arg2='b', arg1='a') A. is an example of a function call using keyword arguments. B. is an example of a function call using default values. C. both A & B
31. The following code compiles in Python except for the marked line. Because of this, what do you know? def fun1(stuff): result = stuff + 5 fun1(5) # this is OK # fun1('a') # this is not OK A. Python uses dynamic duck typing and is not strongly typed. B. Python uses dynamic duck typing and is strongly typed. C. Python uses static typing and is strongly typed.
32. The following C# code will produce a compilation error. Why? double foo(double a, out double b){ // default mode in C# is IN a = b; return 0; } A. an OUT mode parameter cannot be an rvalue before it is an lvalue. B. an IN mode parameter cannot be an lvalue. C. both A & B
33. In Java all parameters are pass-by-value (there is no C++ & type in Java). Because of this, what will the name of Dog c be after calling foo(c)? public static void main (String[] args) { Dog c = new Dog("Fido"); foo(c); } public static void foo(Dog d) { d.setName("Fifi"); d = new Dog("Spot"); } A. Fido B. Fifi C. Spot
The next questions refer to function swap() below. This is pseudo-code. You do not know which type of parameter passing mechanism will be used. swap (a, b) { var temp = a; a = b; b = temp; } Sample function execution: value = 2, List = {1,3,5,7,9}; swap(value, List[0]) swap(List[0], List[1]) swap(value, List[value])
34. If the parameters to swap() use the modes swap (in out a, in b), List is unchanged after the three calls to swap.
35. If the parameters to swap() use the modes swap (in a, in out b), the value of List at the end of the three calls to swap is A. {1,3,5,7,9} B. {2,2,2,7,9} C. {3,1,5,7,9}
36. If both parameters to swap() are pass by value-result, the value of List at the end of the three calls to swap() is A. {1,3,5,7,9} B. {2,2,2,7,9} C. {3,1,5,7,9}
37. Which of the following mechanisms will produce the same results after three calls to swap? Assume value and List[] are passed with the same mechanism. A. pass by value and pass by value-result B. pass by value-result and pass by reference C. pass by value and pass by result
Right: Wrong: Percent: (Must be 100% for credit)
Errors:
Name (first name only): Sleipnir Username: 3-digit ID: