Programming Languages [ch. 9]

Programming Languages [ch. 9]

memorize.aimemorize.ai (lvl 286)
Section 1

Preview this deck

What type of parameter passing mode has no side effects?

Front

Star 0%
Star 0%
Star 0%
Star 0%
Star 0%

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Active users

0

All-time users

0

Favorites

0

Last updated

6 years ago

Date created

Mar 1, 2020

Cards (37)

Section 1

(37 cards)

What type of parameter passing mode has no side effects?

Front

A. in mode

Back

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)?

Front

C. both A & B

Back

Select the true statement that describes how string arrays are passed in C.

Front

A. If the parameter is char[] the address of the array is passed by value.

Back

Accesses to static local variables are slightly more efficient than accesses to stack-dynamic local variables because a reference to a

Front

C. both statements are true

Back

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
"; }

Front

C. both A & B

Back

What statements are true concerning positional binding for parameters?

Front

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.

Back

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]) If both parameters to swap() are pass by value-result, the value of List at the end of the three calls to swap() is

Front

C. {3,1,5,7,9}

Back

In C/C++, the default address binding for non-static variables that are local to a subroutine is

Front

B. stack dynamic

Back

Which of the following are design issues for procedures?

Front

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?

Back

Which is an example of parametric polymorphism?

Front

A. a template function in C++

Back

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

Front

B. Python uses dynamic duck typing and is strongly typed.

Back

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]) 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.

Front

B. pass by value-result and pass by reference

Back

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");

Front

C. both A & B

Back

Why is this function call a compilation error in C#? Foo (out 5); // keyword 'out' specifies an out mode parameter

Front

B. 5 is not a modifiable L-value

Back

function sub1(){ var x = 1; function sub2(){ alert(x); }; function sub3(){ var x = 2; sub4(sub2); }; function sub4(subx){ var x = 3; subx(); } sub3(); }; If '1' is displayed in the alert, the referencing environment of sub2 is

Front

A. the static (lexical) environment of the function definition.

Back

This python function call test_function(arg2='b', arg1='a')

Front

A. is an example of a function call using keyword arguments.

Back

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?

Front

A. foo's local variables B. the return value of the next call to foo C. arguments passed to foo (formal parameters)

Back

All local non-static variables in a procedure are bound to a new storage location for each function call.

Front

T

Back

A coroutine such as implemented in Python may multiple entry points but only one exit point.

Front

F

Back

Which of the following are primary design issues for procedures?

Front

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

Back

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]) If the parameters to swap() use the modes swap (in out a, in b), List is unchanged after the three calls to swap.

Front

T

Back

function sub1(){ var x = 1; function sub2(){ alert(x); }; function sub3(){ var x = 2; sub4(sub2); }; function sub4(subx){ var x = 3; subx(); } sub3(); }; If '2' is displayed in the alert, the referencing environment of sub2 is

Front

C. the static environment of sub2 as an actual argument.

Back

Sample function execution: value = 2, List = {1,3,5,7,9}; swap(value, List[0]) swap(List[0], List[1]) swap(value, List[value]) 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

Front

B. {2,2,2,7,9}

Back

Which of the following are primary design issues for procedures?

Front

B. Can procedures be overloaded? C. Can procedures be generic? D. Can you have nested procedures?

Back

function sub1(){ var x = 1; function sub2(){ alert(x); }; function sub3(){ var x = 2; sub4(sub2); }; function sub4(subx){ var x = 3; subx(); } sub3(); }; If '3' is displayed in the alert, the referencing environment of sub2 is

Front

B. the dynamic environment of the function execution.

Back

A default value for a subroutine parameter if supported must be attached to

Front

B. the formal parameter.

Back

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"); }

Front

B. Fifi

Back

Which two languages support two-way parameter passing?

Front

A. Fortran C. C++

Back

Which parameter passing mechanism supports one-way parameter passing only?

Front

C. both A and B

Back

In C++ pass by reference, the address of the actual parameter is the same as the address of the formal parameter.

Front

T

Back

What is true about the in out mode mechanism of pass-by-reference in C++ ?

Front

A. Any change made to the formal parameter in the subroutine is made immediately to the actual parameter in the calling program.

Back

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); }

Front

A. line #1 modifies the Stuff object in the caller

Back

Which one of these mechanisms uses the same parameter passing semantics?

Front

B. Pass by value-result and pass by reference

Back

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?

Front

B. the size of every dimension but the first

Back

Which statement are true? In all high-level languages a formal parameter

Front

B. is either a copy of or a reference to an actual parameter. C. name exists only within the scope of the procedure.

Back

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?

Front

C. both A and B are true

Back

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; }

Front

A. an OUT mode parameter cannot be an rvalue before it is an lvalue.

Back