CYBERSECURITY-ARCHITECTURE-AND-ENGINEERING practice question 12 of 30

What is a function of a compiler?

Full set: 232 questions

Domain Cybersecurity Principles

Answer options
A: It translates a source code and creates an executable program that may be run at a later time. Correct answer
B: It takes the most recent instruction and translates it as machine language.
C: It takes a program written in a high-level language and converts it to a different high-level language program.
D: It gathers together multiple executable programs and translates them into a readable format.
Correct Answer:
A. It translates a source code and creates an executable program that may be run at a later time.
Explanation

A compiler is a specialized computer program that translates the entire source code of a program, written in a high-level programming language (like C++ or Java), into a lower-level language, typically machine code. The result of this translation is a standalone executable file. This executable can then be run by a user or another program at a later time, directly on the target computer's processor, without needing the compiler or the original source code again. This "translate-then-run" process is the defining characteristic of a compiler.

Why Incorrect

B. This describes the function of an interpreter, which translates and executes a program one instruction or line at a time, rather than creating a separate executable file beforehand.
C. This describes a source-to-source compiler, also known as a transpiler. While a type of compiler, its primary function is not the general case, which is translation to a lower-level language.
D. This function is more closely related to a linker, which combines multiple object or executable files, or a decompiler, which attempts to reverse the compilation process into a readable format.

References

1. Aho, A. V., Lam, M. S., Sethi, R., & Ullman, J. D. (2007). Compilers: Principles, Techniques, & Tools (2nd ed.). Pearson/Addison Wesley.

In Chapter 1, Section 1.1, "Language Processors," the text states, "a compiler is a program that can read a program in one language — the source language — and translate it into an equivalent program in another language — the target language... If the target program is an executable machine-language program, it can then be called by the user to process inputs and produce outputs." (pp. 1-2). This directly supports the function described in option A.

2. Patterson, D. A., & Hennessy, J. L. (2017). Computer Organization and Design RISC-V Edition: The Hardware Software Interface. Morgan Kaufmann.

Section 2.2, "Instructions: Language of the Computer," explains the compiler's role: "A compiler translates a high-level language program into an assembly language program," which is then assembled into a machine language object file. This process creates the basis for an executable program. (p. 64).

3. MIT OpenCourseWare. (2010). 6.035 Computer Language Engineering, Fall 2010. Massachusetts Institute of Technology.

In Lecture 1, "Introduction and Overview," slide 5 ("Compiler vs. Interpreter") explicitly differentiates the two: "Compiler: translates the entire source program to a target program, which is then executed. Interpreter: directly executes the source program." This confirms that option A describes a compiler and option B describes an interpreter.

Scroll to Top