Sample Mid1
Sample Mid1
SAMPLE
QUESTIONS
MIDTERM EXAM
Scheduled on campus
Time and location not finalized
Content required
Topics 1 – 6 with reference material from the
book (up to datatypes II)
One hour duration
Exam Structure
10 multiple choice questions
4 problems
EXAM MATERIAL
Write/analyse BNF, Convert to EBNF, build a parse tree based on
a grammar and a statement, prove grammar is ambiguous
Write denotational/operational/axiomatic semantics derivations
and rules of given statement(s)
Static vs dynamic scope binding, (value of variable based on
given code)
2d array element indexing
All other material can come in form of MCQ and SAQ
MCQ – Q1
The lifetime of a variable is the time during which
A. The variable is bound to a specific type
B. The variable is bound to a specific name
C. The variable is bound to a specific value
D. None of the above
MCQ – Q1
The lifetime of a variable is the time during which
A. The variable is bound to a specific type
B. The variable is bound to a specific name
C. The variable is bound to a specific value
D. None of the above
MCQ – Q2
A binding is dynamic if
A. It occurs before run time and remains unchanged throughout
program execution
B. It occurs before run time and changes throughout program
execution
C. It occurs during runtime and remains unchanged throughout
program execution
D. It occurs during runtime and changes through program execution
MCQ – Q2
A binding is dynamic if
A. It occurs before run time and remains unchanged throughout
program execution
B. It occurs before run time and changes throughout program
execution
C. It occurs during runtime and remains unchanged throughout
program execution
D. It occurs during runtime and changes through program execution
MCQ - Q3
Explicit Heap Dynamic allocation is used when:
A. The developer wants to allocate an object during runtime
B. The local variables of a function are allocated
C. An array whose length is known during a block activation
D. A type is bound to a variable during execution
MCQ - Q3
Explicit Heap Dynamic allocation is used when:
A. The developer wants to allocate an object during runtime
B. The local variables of a function are allocated
C. An array whose length is known during a block activation
D. A type is bound to a variable during execution
MCQ – Q4
A grammar is said to be ambiguous if:
A. Two production rules have the same meaning
B. There are two ways of writing a given production rule
C. A string in the language described by the grammar has two parse
trees.
D. There are two non-terminals on the left-hand side of the production
E. None of the above.
MCQ – Q4
A grammar is said to be ambiguous if:
A. Two production rules have the same meaning
B. There are two ways of writing a given production rule
C. A string in the language described by the grammar has two parse
trees.
D. There are two non-terminals on the left-hand side of the production
E. None of the above.
SAQ – Q1
State True or False. If False correct.
a) The designers of Java traded reliability for execution efficiency,
so Java programs execute faster than semantically equivalent C
programs ( )
b) ADA supports Jagged arrays, where row lengths do not have to
be the same ( )
c) Java is a strongly typed programming language ( )
SAQ – Q1
State True or False. If False correct.
a) The designers of Java traded reliability for execution efficiency,
so Java programs execute faster slower than semantically
equivalent C programs
(F)
b) ADA Java supports Jagged arrays, where row lengths do not
have to be the same ( F )
c) Java is a strongly typed programming language ( T )
SAQ – Q2
Consider the following function
void foo(int x, int y, int z){
int a, b, c;
a = x + 1;
b = y + 2;
c = z + 3;
}
When foo finishes, its local variables (a, b and c) no longer exist. Why don’t we have to
manually deallocate the space that they occupy?
(b)
𝑀𝑑𝑒𝑐 ′1′ = 1
𝑀𝑑𝑒𝑐 𝑛𝑢𝑚𝑏𝑒𝑟 ′3′ = 10 ∗ 𝑀𝑑𝑒𝑐 (𝑛𝑢𝑚𝑏𝑒𝑟) + 3
𝑀𝑑𝑒𝑐 𝑛𝑢𝑚𝑏𝑒𝑟 ′2′ = 10 ∗ 𝑀𝑑𝑒𝑐 (𝑛𝑢𝑚𝑏𝑒𝑟) + 2
Derivation:
𝑀𝑑𝑒𝑐 (‘1’’2’’3’)= 10 ∗ 𝑀𝑑𝑒𝑐 (‘1’’2’) + 3
= 10 ∗ 10 ∗ 𝑀𝑑𝑒𝑐 ‘1’ + 2 + 3
= 10 ∗ 10 ∗ 1 + 2 + 3
= 10 ∗ 12 + 3 = 120 + 3 = 123
PROBLEM