wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

PL Final Exam

Total questions: 70

Worksheet time: 35mins

Name
Class
Date
1.

The region or part of a program where a variable is accessible.

a)

Scope

b)

Loop

c)

Function

d)

Class

2.

The ability of a language to allow a small number of constructs to be combined freely without restrictions.

a)

Orthogonality

b)

Encapsulation

c)

Polymorphism

d)

Inheritance

3.

The type of semantics that describes how a program executes step-by-step.

a)

Operational Semantics

b)

Denotational Semantics

c)

Axiomatic Semantics

d)

Contextual Semantics

4.

The degree to which programs perform correctly and consistently under all circumstances.

a)

Reliability

b)

Portability

c)

Efficiency

d)

Maintainability

5.

What x:=x+1x:=x+1 represents in Operational Semantics if the initial state is S(x=5).

a)

S(x=6)

b)

S(x=5)

c)

S(x=4)

d)

S(x=7)

6.

The process of associating a variable name with a memory location or value.

a)

Binding

b)

Casting

c)

Looping

d)

Referencing

7.

The type of semantics that uses Hoare Triples ( {P}\{P\} \text{statement} {Q}\{Q\} ) to describe program correctness.

a)

Axiomatic Semantics

b)

Operational Semantics

c)

Denotational Semantics

d)

Syntax-Directed Semantics

8.

The concept that allows inner scopes to access variables from outer scopes, but not vice versa.

a)

Static Scoping

b)

Dynamic Binding

c)

Lexical Analysis

d)

Runtime Polymorphism

9.

The specific component of an Activation Record that points to the caller's activation record.

a)

Dynamic Link

b)

Return Address

c)

Control Link

d)

Access Link

10.

The binding time for the meaning of the plus operator (+) as addition.

a)

Language Definition Time

b)

Compilation Time

c)

Linking Time

d)

Execution Time

11.

The type of typing where errors may appear only during runtime.

a)

Dynamic Typing

b)

Static Typing

c)

Strong Typing

d)

Duck Typing

12.

The degree to which a language allows programmers to express ideas or structures in code easily.

a)

Readability

b)

Efficiency

c)

Portability

d)

Security

13.

The logical assertion that must be true before the execution of a statement in Axiomatic Semantics.

a)

Precondition

b)

Postcondition

c)

Invariant

d)

Predicate

14.

The concept of an Activation Record that allows a function to return to the correct place after execution.

a)

Return Address

b)

Stack Pointer

c)

Frame Pointer

d)

Local Variables

15.

The characteristic of a language that determines if it allows implicit conversions between different data types.

a)

Type Compatibility

b)

Syntax Highlighting

c)

Memory Allocation

d)

Error Handling

16.

The concept described by the phrase, "Variables declared inside a block shadow variables with the same name in outer scopes".

a)

Variable Shadowing

b)

Variable Hoisting

c)

Variable Scoping

d)

Variable Binding

17.

The total expense of using, developing, and maintaining code in a language.

a)

Cost

b)

Syntax

c)

Performance

d)

Portability

18.

The type of typing where variable types must be declared explicitly.

a)

Static Typing

b)

Dynamic Typing

c)

Duck Typing

d)

Implicit Typing

19.

The type of semantics that describes what a program computes as a mathematical function.

a)

Denotational Semantics

b)

Operational Semantics

c)

Axiomatic Semantics

d)

Syntactic Semantics

20.

Binding that happens before runtime, such as variable types in the C language.

a)

Static Binding

b)

Dynamic Binding

c)

Late Binding

d)

Runtime Binding

21.

The primary focus of Syntax in programming languages is:

a)

What the program actually does

b)

How the program is written

c)

Why the program is correct

d)

The mathematical function it computes

22.

A primary feature of high writability languages is:

a)

Static type checking

b)

Low control over the machine

c)

Rich built-in operations and concise syntax

d)

Enforced block scoping

23.

In Operational Semantics, behavior is defined by changes in:

a)

Mathematical function

b)

Hoare Triple

c)

State (State transitions)

d)

Activation Record

24.

Python’s type system is:

a)

Static & Weakly Typed

b)

Dynamic & Weakly Typed

c)

Static & Strongly Typed

d)

Dynamic & Strongly Typed

25.

Major contributor to a language’s Maintenance Cost:

a)

Speed of execution

b)

Low writability

c)

High readability

d)

Learning curve

26.

Direction: Encircle or underline the correct answer. 26. Primary representation in Denotational Semantics:

a)

State transition arrow

b)

Hoare Triple

c)

Mathematical function

d)

Runtime stack

27.

Static (Lexical) Scoping means:

a)

Depends on call sequence

b)

Types fixed at runtime

c)

Depends on code structure

d)

Binding at compile time

28.

Handling exceptions gracefully increases:

a)

Readability

b)

Writability

c)

Reliability

d)

Cost

29.

Memory block created for a function call is:

a)

Access Link

b)

Activation Record

c)

Global Scope

d)

Control Link

30.

Language less reliable due to pointers/manual memory:

a)

Python

b)

Java

c)

C

d)

C++

31.

In Hoare Triple {P} statement {Q}, correctness is guaranteed by:

a)

P

b)

Statement

c)

Q

d)

Whole triple

32.

Static typing advantage:

a)

Errors caught early (compile-time)

b)

Easier to modify

c)

Types change at runtime

d)

Less code

33.

Dynamic (Late) Binding occurs at:

a)

Compile Time

b)

Link Time

c)

Language Definition

d)

Run Time

34.

Direction: Encircle or underline the correct answer. 34. Global variable declared:

a)

Inside loop

b)

Inside function

c)

Outside all functions

d)

In another file

35.

Real-life analogy for Operational Semantics:

a)

Contract

b)

Cooking recipe

c)

Mathematical function

d)

High-level summary

36.

Access Link points to:

a)

Next line

b)

Caller’s record

c)

Non-local variables

d)

Saved registers

37.

Trade-off with high writability:

a)

High readability

b)

Control over the machine

c)

Low cost

d)

Expressivity

38.

When two functions call each other recursively:

a)

One record used

b)

Only parameters saved

c)

Multiple activation records created

d)

Uses heap

39.

Expressivity feature improving writability:

a)

Exception handling

b)

Static type checking

c)

List comprehensions

d)

Block scoping

40.

In strongly typed languages, "5" + 2 results in:

a)

Crash

b)

Implicit conversion

c)

TypeError

d)

Warning

41.

Semantics defines the meaning or behavior of programs, while Syntax defines how programs are written (the form).

a)

True

b)

False

42.

An advantage of Operational Semantics is that it abstracts away execution details, focusing only on the result.

a)

True

b)

False

43.

In Denotational Semantics, the sequence of statements x:=3;y:=x+2;x:=3; y:=x+2; is evaluated by applying the meaning of y:=x+2y:=x+2 first, then x:=3x:=3 .

a)

True

b)

False

44.

Readability is considered less important than Writability because a program spends most of its life being executed by machines.

a)

True

b)

False

45.

Simplicity is a factor that improves both Readability and Writability.

a)

True

b)

False

46.

The Execution Cost of a language refers to the time and effort required to learn it.

a)

True

b)

False

47.

A language with Weak Typing enforces strict type compatibility and results in more type errors.

a)

True

b)

False

48.

In a language with Dynamic Typing, the type of a variable can change during runtime.

a)

True

b)

False

49.

In static scoping, the compiler determines the scope from the code layout (lexical structure).

a)

True

b)

False

50.

The Control Link in an Activation Record points to non-local variables.

a)

True

b)

False

51.

Static (Early) Binding is generally associated with higher performance because decisions are made before runtime.

a)

True

b)

False

52.

In the Hoare Triple extstatement ext{statement} , the Postcondition QQ defines what must be true before execution.

a)

True

b)

False

53.

The availability of clear and high-level data structures (like lists and dictionaries) improves a language's Readability.

a)

True

b)

False

54.

Recursion requires the creation of multiple Activation Records for the same function on the runtime stack.

a)

True

b)

False

55.

The total cost of a language includes only the time taken to design, code, and debug (Development Cost).

a)

True

b)

False

56.

Aliasing Control is a factor that reduces unintended side effects from shared references, thereby improving Reliability.

a)

True

b)

False

57.

Dynamic Scoping is used in modern languages like Python and C++.

a)

True

b)

False

58.

The expression $[\begin{matrix}x&=&x+1&](s)&=s[x\mapsto&s(x)+1\end{matrix}]$ is a representation used in Denotational Semantics.

a)

True

b)

False

59.

A Local Scope variable declared inside a function is accessible anywhere in the program.

a)

True

b)

False

60.

Improving one evaluation criterion (e.g., Readability) often requires a trade-off that reduces another (e.g., Control over the machine)

a)

True

b)

False

61.

Direction: Fill in the missing part ({ ? }) for the assignment statement using the Assignment Axiom of Axiomatic Semantics.

No. 61-62
Precondition (P): { ? }
Statement (v:=e): x := x + 5
Postcondition (Q): { x = 12 }
What is the missing precondition?

a)

{ x = 7 }

b)

{ x = 12 }

c)

{ x = 17 }

d)

{ x = 5 }

62.

Direction: Fill in the missing part ({ ? }) for the assignment statement using the Assignment Axiom of Axiomatic Semantics.

No. 63-64
Precondition (P): { y = 3 }
Statement (v:=e): y := y * 4
Postcondition (Q): { ? }
What is the missing postcondition?

a)

{ y = 12 }

b)

{ y = 7 }

c)

{ y = 3 }

d)

{ y = 4 }

63.

Direction: Fill in the missing part ({ ? }) for the assignment statement using the Assignment Axiom of Axiomatic Semantics.

No. 65-66
Precondition (P): { a = 9 }
Statement (v:=e): { ? }
Postcondition (Q): { a = 1 }
What is the missing statement?

a)

a := 1

b)

a := 9

c)

a := a + 1

d)

a := 0

64.

Direction: Fill in the missing part ({ ? }) for the assignment statement using the Assignment Axiom of Axiomatic Semantics.

No. 67-68
Statement (v:=e): z := z - 3
Postcondition (Q): { z < 5 }
What is the missing precondition?

a)

{ z < 8 }

b)

{ z < 2 }

c)

{ z < 5 }

d)

{ z < 3 }

65.

Direction: Fill in the missing part ({ ? }) for the assignment statement using the Assignment Axiom of Axiomatic Semantics.

No. 69-70
Precondition (P): { p = 10 }
Statement (v:=e): p := p / 2
Postcondition (Q): { ? }
What is the missing postcondition?

a)

{ p = 5 }

b)

{ p = 20 }

c)

{ p = 2 }

d)

{ p = 10 }

66.

Direction: Fill in the missing part ({ ? }) for the assignment statement using the Assignment Axiom of Axiomatic Semantics.

No. 71-72
Precondition (P): { b = 2 }
Statement (v:=e): { ? }
Postcondition (Q): { b = 16 }
What is the missing statement?

a)

b := 16

b)

b := 2

c)

b := b + 2

d)

b := 8

67.

Direction: Fill in the missing part ({ ? }) for the assignment statement using the Assignment Axiom of Axiomatic Semantics.

No. 73-74
Precondition (P): { ? }
Statement (v:=e): c := d
Postcondition (Q): { c = 20 }
What is the missing precondition?

a)

{ d = 20 }

b)

{ c = 20 }

c)

{ d = c }

d)

{ c = d }

68.

Direction: Fill in the missing part ({ ? }) for the assignment statement using the Assignment Axiom of Axiomatic Semantics.

No. 75-76
Precondition (P): { x > 0 }
Statement (v:=e): x := x + 1
Postcondition (Q): { ? }
What is the missing postcondition?

a)

{ x > 1 }

b)

{ x > 0 }

c)

{ x >= 0 }

d)

{ x < 0 }

69.

Direction: Fill in the missing part ({ ? }) for the assignment statement using the Assignment Axiom of Axiomatic Semantics.

No. 77-78
Precondition (P): { k = 5 }
Statement (v:=e): { ? }
Postcondition (Q): { k = 5 }
What is the missing statement?

a)

k := 5

b)

k := 0

c)

k := k + 1

d)

k := 10

70.

Direction: Fill in the missing part ({ ? }) for the assignment statement using the Assignment Axiom of Axiomatic Semantics.

No. 79-80
Statement (v:=e): m := 2
Postcondition (Q): { m != 3 }
What is the missing precondition?

a)

{ } (any value for m, since m := 2 will always make m != 3)

b)

{ m = 3 }

c)

{ m > 2 }

d)

{ m < 2 }