Compilers

What is the main benefit of compile-time type checking in a statically typed language?

  1. AMismatched operations and assignments are found before the program runs
  2. BType declarations disappear, so programs always get shorter
  3. CEvery error that could occur at run time is eliminated at compile time
Show answer and explanation

Answer: A. Mismatched operations and assignments are found before the program runs

Type checking catches errors such as adding an integer to a string or passing an argument of the wrong type before the program runs. Errors are found early, and type information also helps the compiler choose efficient machine code. It cannot, however, eliminate value-dependent errors such as division by zero or out-of-bounds array accesses. Declaring types does not necessarily make programs shorter either.

  • A. Correct. Type errors are found before execution.
  • B. Declaring types does not necessarily shorten programs.
  • C. Value-dependent run-time errors cannot be eliminated.
Practice this topic Back to topic

More Compilers questions

  1. What is commonly used to express the rules for recognizing tokens in lexical analysis?
  2. Which kind of grammar is used to describe most programming languages and underlies parsing?
  3. What does the abstract syntax tree for the expression 2 + 3 * 4 look like?
  4. Which describes three-address code, a kind of intermediate representation?
  5. What does liveness analysis, done in preparation for register allocation, determine?