Week 6
1 Block structures
1) Organize related declarations and statements.
2) Can be nested only a limited (though large) number of times.
3) Contain only statements - declarations must be at the class or method level.
4) In some languages limit the kinds of declarations they may contain (e.g., no function declarations/implementations).
5) None of the above
2 Declarations in a block are
1) visible only within that block - and not in nested blocks.
2) only allocated on the run-time stack (for non-static variables).
3) visible in nested blocks unless hidden by nested declarations.
4) only allocated on from the heap (for non-static variables).
5) None of the above
3 The scope and lifetime of a variable declaration
1) Are always the same.
2) Are never the same.
3) Can be different if the variable declaration is hidden in a nested block.
4) Can be different if the value is allocated in the heap.
5) None of the above
4 The scope of a declaration is
1) The region of the program text the variable resides within the symbol table.
2) The time period in a running program that the variable/value has allocated space.
3) The region of the program text in which the declaration is visible.
4) Is the same as the lifetime of the variable declaration.
5) None of the above
5 The lifetime of a declaration is
1) The region of the program text the variable resides within the symbol table.
2) The time period in a running program that the variable/value has allocated space.
3) The region of the program text in which the declaration is visible.
4) Is the same as the scope of the variable declaration.
5) None of the above
6 Which of these are ways to make the scope and lifetime of a variable declaration different?
1) Hide the variable name in the outer scope by declaring a variable of the same name within a nested scope.
2) For most compilers, declare a variable within an anonymous block (so that it's storage allocation would occur within the named "parent" block).
3) Cannot be done, the scope and lifetime of variable declarations are always the same.
4) Declare the variable as static within a nested scope (e.g., a function).
5) None of the above
7 Unless specifically indicated otherwise, block structured languages (e.g., Java, C++) nearly always allocate memory for variable declarations within blocks
1) statically (to reduce the memory footprint).
2) on the run-time stack.
3) in the heap.
4) either in the heap or run-time stack, whichever has the most space remaining.
5) None of the above
8 A characteristic of block structured languages is that of the declarations supported by the language (e.g., variable, class, function)
1) variable declarations are always allowed within a block.
2) only function declarations (but not their implementations) may appear within a block.
3) type (and class) declarations may be given, but only if they are anonymous.
4) all may appear within a block.
5) None of the above
9 Symbol tables are used by the compiler
1) Only as a convenience to make compilation faster.
2) To keep track of declarations and their scope.
3) To determine when declared variables should be deallocated.
4) To ensure that the scope and lifetimes of declarations are the same (part of semantic analysis).
5) None of the above
10 Symbol tables are often implemented as
1) Stacks
2) Priority queues
3) Bucket hash tables
4) Association lists
5) None of the above
11 In a symbol table implemented via bucket hashing, declarations of the same name are
1) Always placed in the same bucket.
2) Always placed in different buckets.
3) Sometimes placed in the same bucket.
4) Never allowed.
5) None of the above
12 In a bucket hashing symbol table
1) New entries are always placed at the end of the bucket/list.
2) New entries are always placed at the beginning of the bucket/list.
3) The first entry in every bucket/list is deleted when a scope is exited.
4) The last entry in every bucket/list is deleted when a scope is exited.
5) None of the above
13 Bucket hashing is well suited for symbol table implementations because
1) Inserting new declarations takes constant, O(1), time.
2) When exiting a scope, declaration removal takes O(n^2) time where n is the number of declarations to be removed.
3) Name lookup is fast since it must be the first item in the bucket/list.
4) Nested declarations automatically hide previous declarations of the same name (which will appear later in the bucket/list).
5) None of the above
{"name":"Week 6", "url":"https://www.quiz-maker.com/QPREVIEW","txt":"1 Block structures, 2 Declarations in a block are, 3 The scope and lifetime of a variable declaration","img":"https://www.quiz-maker.com/3012/images/ogquiz.png"}
More Quizzes
Quiz
10510
¿Cómo Aprendes Mejor?
14723
Music quiz
630
AG
420
Aquestria world 1 area 1 part 2
15815
Diabetes Assessment 2 : Version 2
27140
Let's Get Quizzical!
13616
GREEN DAY Trivia
1050
Interior Plains Calgary Alberta
6310
Are you kili or gandalf OR LEGOLAS?
320
Luciana
10510
Let me judge you 1-10 based on how you answer these!
5218