Foundations-of-Computer-Science practice question 15 of 15

Why are comments used in source code?

Full set: 71 questions
Answer options
A:

A. To explain code for humans without affecting program execution

Correct answer
B:

B. To force the compiler to skip the file permanently

C:

C. To encrypt variables before runtime

D:

D. To reduce the need for meaningful names

Correct Answer:
A. A. To explain code for humans without affecting program execution
Explanation

Comments are annotations within the source code that are intended for human readers. Their primary purpose is to clarify the code's logic, document its purpose, or provide usage instructions. Compilers and interpreters are designed to ignore comments, so they have no effect on the final executable program. This allows developers to write explanatory text that improves code maintainability and readability without altering its functionality.

Why Incorrect

B. Comments are ignored during compilation, but they do not cause the compiler to skip the entire source file.
C. Comments are plain text and have no role in cryptographic operations like encrypting variables. Encryption is handled by specific code logic.
D. While comments explain code, they are not a substitute for clear, meaningful variable and function names, which is a core principle of clean code.

References

1. Kernighan, B. W., & Ritchie, D. M. (1988). The C Programming Language (2nd ed.). Prentice Hall. (Section 1.2, p. 9, introduces comments / ... / as notes that are ignored by the compiler.)

2. Python Software Foundation. (n.d.). Python 3.12.3 documentation. The Python Tutorial, Section 3.1.1: Numbers. (Describes comments starting with the hash character # and explains they are for clarifying code and are ignored by the interpreter.)

3. Martin, R. C. (2008). Clean Code: A Handbook of Agile Software Craftsmanship. Prentice Hall. (Chapter 4: "Comments," emphasizes that comments exist to explain code that cannot be made self-explanatory.)

Scroll to Top