Compiler Design Banner

Compiler Design Multiple Choice Questions (MCQs) and Answers

Master Compiler Design with Practice MCQs. Explore our curated collection of Multiple Choice Questions. Ideal for placement and interview preparation, our questions range from basic to advanced, ensuring comprehensive coverage of Compiler Design concepts. Begin your placement preparation journey now!

Q61

Q61 Why is intermediate code generation important in a compiler?

A

To simplify parsing

B

To optimize syntax trees

C

To achieve platform independence

D

To directly execute programs

Q62

Q62 What is the challenge of converting an abstract syntax tree into intermediate code?

A

Handling syntax errors

B

Resolving scope rules

C

Preserving the order of operations

D

Detecting type mismatches

Q63

Q63 Which intermediate representation would result from the expression 'a + b * c'?

A

a b c * +

B

a + b c *

C

b c + a *

D

a * b + c

Q64

Q64 Given the quadruple representation for x = a + b * c, what would be the last instruction?

A

x = a + b * c

B

t1 = b * c

C

t2 = a + t1

D

x = t2

Q65

Q65 What is the three-address code for the statement: z = (x + y) * w?

A

t1 = x + y; z = t1 * w

B

t1 = x + y; t2 = t1 * w; z = t2

C

z = (x + y) * w

D

t1 = x * w + y

Q66

Q66 What is the postfix representation of the expression: (a + b) * (c - d)?

A

a b + c d - *

B

a b c d + - *

C

a + b c - d *

D

a b c d * + -

Q67

Q67 What error is detected if a variable is used in intermediate code without initialization?

A

Syntax error

B

Semantic error

C

Initialization error

D

Lexical error

Q68

Q68 What might cause an 'undefined temporary variable' error during intermediate code generation?

A

A missing temporary variable declaration

B

Incorrect operator precedence

C

Improper grammar definition

D

Invalid target machine code

Q69

Q69 How can intermediate code generation handle expressions with multiple operators?

A

By using operator precedence rules

B

By creating new grammars

C

By generating random code

D

By skipping intermediate steps

Q70

Q70 What is the main goal of code optimization in a compiler?

A

To reduce code size

B

To improve execution speed

C

To ensure correctness

D

Both reduce code size and improve execution speed

Q71

Q71 Which of the following is a local optimization technique?

A

Dead code elimination

B

Loop unrolling

C

Function inlining

D

Common subexpression elimination

Q72

Q72 Which type of optimization requires control flow analysis?

A

Global optimization

B

Local optimization

C

Peephole optimization

D

Intermediate code generation

Q73

Q73 What is loop unrolling in the context of code optimization?

A

Reducing loop iterations

B

Combining multiple loops

C

Rewriting loops to execute fewer iterations

D

Removing loops altogether

Q74

Q74 Which optimization technique focuses on eliminating redundant code computations?

A

Constant folding

B

Loop unrolling

C

Common subexpression elimination

D

Dead code elimination

Q75

Q75 What is the optimized form of the expression: a = b + c; d = b + c;?

A

a = b + c; d = a;

B

a = b + c; d = b + c;

C

a = d = b + c;

D

No optimization possible

Q76

Q76 Which loop optimization is applied to: for(i=0; i<10; i++) sum += i;?

A

Constant folding

B

Loop unrolling

C

Loop fusion

D

Dead code elimination

Q77

Q77 What is the result of applying constant folding to the code: int x = 5 * 2;?

A

int x = 5 * 2;

B

int x = 10;

C

No change

D

Compilation error

Q78

Q78 What is the possible issue if loop unrolling results in increased code size?

A

Poor register allocation

B

Memory allocation failure

C

Code bloat

D

Unoptimized machine code

Q79

Q79 What type of error occurs if dead code is incorrectly eliminated?

A

Semantic error

B

Logical error

C

Runtime error

D

Syntax error

Q80

Q80 How can global optimization cause unintended side effects?

A

By modifying local variables

B

By ignoring variable scopes

C

By reordering instructions

D

By skipping error checks

Q81

Q81 What is the primary goal of code generation in a compiler?

A

To translate intermediate code to machine code

B

To optimize syntax trees

C

To validate program logic

D

To check for runtime errors

Q82

Q82 Which of the following is a challenge in code generation?

A

Parsing the input

B

Optimizing intermediate code

C

Efficient register allocation

D

Ensuring lexical correctness

Q83

Q83 What is instruction selection in the context of code generation?

A

Choosing instructions based on syntax

B

Choosing efficient machine instructions

C

Selecting intermediate code

D

Selecting error-handling code

Q84

Q84 Which of the following issues can occur during register allocation?

A

Code redundancy

B

Register spill

C

Incorrect parsing

D

Invalid syntax

Q85

Q85 Why is target machine architecture important in code generation?

A

To optimize source code

B

To ensure platform independence

C

To map intermediate code to machine code

D

To validate grammar rules

Q86

Q86 What is the generated machine code for the intermediate instruction: t1 = a + b?

A

ADD a, b, t1

B

ADD t1, a, b

C

LOAD t1, a

D

STORE t1, b

Q87

Q87 How is the instruction 'x = y + z' translated to machine code using two-address instructions?

A

ADD y, z, x

B

LOAD x, y; ADD x, z

C

LOAD y; ADD y, z; STORE x

D

None of the above

Q88

Q88 What is the output of translating the expression (a + b) * c into three-address machine code?

A

t1 = a + b; t2 = t1 * c

B

t1 = a * c; t2 = t1 + b

C

t1 = a + c; t2 = t1 * b

D

t1 = a * b; t2 = t1 + c

Q89

Q89 What is the most likely cause of 'unmapped variable' error during code generation?

A

Undefined variable in source code

B

Syntax error in intermediate code

C

Unallocated register for a variable

D

Machine code overflow

Q90

Q90 Why might a 'segmentation fault' occur in generated machine code?

A

Incorrect syntax in source code

B

Accessing invalid memory locations

C

Loop unrolling

D

Register spill

ad verticalad vertical
ad