Name Binding 2

Given the following C code,
int p[10]; int* foo(int x) { static int q[10]; int r[10]; int *s = new int[10]; switch (x) { case 1: return p; case 2: return q; case 3: return r; case 4: return s; default: foo(x+1); } } which following statements are wrong? Check all that apply o o o o o o o o Array p is allocated in static memory Array p is allocated in stack memory Array q is allocated in static memory Array q is allocated in stack memory Array r is allocated in stack memory Array r is allocated in heap memory Array pointed by s is allocated in stack memory Array pointed by s is allocated in heap memory which following statements are correct? Check all that apply The lifetime of array p is the lifetime of foo The lifetime of array p is the lifetime of whole program The lifetime of array q is the lifetime of foo The lifetime of array q is the lifetime of whole program The lifetime of array r is the lifetime of foo The lifetime of array r is the lifetime of whole program The lifetime of the array pointed by s is the lifetime of foo The lifetime of the array pointed by s is the lifetime of whole program which statements may cause runtime problem? return p return q return r return s when foo is called recursively, which arrays are the same among foo execution? Check all that apply p q

o o o o o o o o

o o o o

o o

EQ. o o o o o a reserved word a keyword an identifier a password a wrong word What is the binding time of the real address of variable count in the following C code? static int count. IF is called IF (IF . THEN) THEN .o o r s Which array may become garbage? Check all that apply p q r s o o o o Name Binding 1 Which of the following is not an attribute of a variable? o o o o o name address type value length In Fortran... o o o o o programming compiling loading running implementation What is the binding time of the type of a variable in Javascript? o o programming compiling . a valid IF statement can be written as follows.

} 1.int *q = p. sub1 and sub2 Scope of x declared at 1 is sub2 and main The referencing environment of main is x declared at 1. select all statements that are correct Scope of main is x declared at 1.o o o loading running implementation What will happen when executing the following code? int *p=new int. Assume that the program is written in a static-scoping language. Assume that the program is written in a static-scoping language and calling chain is main to sub1 to sub2. which declaration is referred by x in sub2? o o o o it is referred to x that is declared at 1 it is referred to x that is declared at 2 it is referred to x that is declared at 1 in one time and at 2 in another time error message: x is undeclared 2.2 and 3 var x. } procedure sub2() { x // use x } main(){ call sub1(). //1 procedure sub1() { var x. o o o o o alias polymorphism dangling reference garbage undeclared pointer Scope and Referencing Environment The following program is used to question 1.//2 call sub2(). o o o o o o o . sub1 and sub2. *p = 1. which declaration of x is referred by x in sub2? it is referred to x that is declared at 1 it is referred to x that is declared at 2 it is referred to x that is declared at 1 in one time and at 2 in another time error message: x is undeclared 3.If the program is written in a dynamic-scoping language and calling chain is main to sub1 to sub2.

o The referencing environment of x declared at is sub2 and main The following code is used to illustrate question 4 r x.// Using x is allowed x = 1. //redeclare x as global x = 2. assigning to x is allowed 4.// Assigning to x is NOT allowed global x.. // x is global function foo() { var y = x . some named constants are declared with const or readonly. In which language can a global variable be referenced in a function but not to be assigned in a function without redeclared as global inside the function? o o o o o Java Scala Javascript Python PHP 5. // Now. In C#. Which statements are correct? Named constant declared with const is statically bound to its value Named constant declared with const is dynamically bound to its value Named constant declared with readonly is statically bound to its value Named constant declared with readonly is dynamically bound to its value o o o o .

Sign up to vote on this title
UsefulNot useful