Chapter 2 Quiz

Test your understanding of the concepts covered in this chapter. Answers appear at the end.


Question 1. What is the command to compile a Pascal source file called myprogram.pas using the Free Pascal Compiler from the command line?

A) pascal myprogram.pas B) fpc myprogram.pas C) compile myprogram.pas D) run myprogram.pas


Question 2. Which of the following is the correct order of the compilation pipeline?

A) Linking → Compilation → Execution B) Compilation → Execution → Linking C) Compilation → Linking → Execution D) Execution → Compilation → Linking


Question 3. What does the linker do?

A) Checks your program for syntax errors B) Combines object code with the runtime library to produce an executable C) Runs your program line by line D) Converts your executable back into source code


Question 4. Every Pascal program must end with:

A) end; B) end: C) end. D) end


Question 5. What is the difference between WriteLn and Write?

A) WriteLn is faster than Write B) WriteLn adds a newline after the output; Write does not C) Write can only output numbers; WriteLn can output strings D) There is no difference; they are synonyms


Question 6. In Pascal, string literals are enclosed in:

A) Double quotes: "Hello" B) Single quotes: 'Hello' C) Backticks: `Hello` D) Angle brackets: <Hello>


Question 7. What does the uses clause in a Pascal program do?

A) Declares variables the program will use B) Imports units (library modules) into the program C) Lists the files the program will read from disk D) Specifies which compiler to use


Question 8. Which of the following is NOT a valid Pascal comment?

A) { This is a comment } B) (* This is a comment *) C) // This is a comment D) /* This is a comment */


Question 9. What does the PATH environment variable control?

A) Where the compiler saves output files B) Which directories the operating system searches for commands C) The maximum file size for Pascal programs D) The color scheme of the terminal


Question 10. What file extension is used for Pascal source code files?

A) .p B) .pascal C) .pas D) .pc


Question 11. When you compile hello.pas, the compiler produces an intermediate file with what extension?

A) .obj B) .o C) .tmp D) .int


Question 12. What happens if you try to compile a program that has a type error (for example, trying to add a string to a number)?

A) The program compiles and crashes when it runs B) The compiler reports an error and does not produce an executable C) The compiler automatically fixes the error D) The program compiles but produces wrong results


Question 13. Which of the following is a valid Pascal program header?

A) program My Program; B) program 2ndProgram; C) program MyProgram; D) Program: MyProgram


Question 14. In the Lazarus IDE, which keyboard shortcut compiles and runs a program?

A) Ctrl+R B) F5 C) F9 D) Ctrl+F5


Question 15. A standalone executable produced by Free Pascal requires which of the following to run on another machine?

A) The Free Pascal compiler must be installed B) The Lazarus IDE must be installed C) A Pascal runtime environment must be installed D) Only the operating system — no additional software is needed


Question 16. What is the purpose of ReadLn; at the end of a console program run from Lazarus?

A) It reads a line of text from a file B) It prevents the terminal window from closing before you can read the output C) It is required by all Pascal programs D) It displays the final line of output


Question 17. Which of the following best describes why Pascal is called a "compiled language"?

A) Because you can compress its source files B) Because the entire source code is translated to machine code before execution begins C) Because it compiles a list of all variables used D) Because it is compatible with other languages


Question 18. You compile a program and the compiler reports: hello.pas(5,12) Error: Identifier not found "WriteLin". What is the most likely problem?

A) The file hello.pas does not exist B) Line 5 has a typo — WriteLin should be WriteLn C) The program is missing a uses clause D) The PATH is not configured correctly



Answer Key

  1. Bfpc myprogram.pas invokes the Free Pascal Compiler on the source file.

  2. C — Compilation (source to object code), then Linking (object code to executable), then Execution (OS runs the executable).

  3. B — The linker combines your compiled object code with the runtime library (which provides built-in procedures like WriteLn) to produce a complete, standalone executable.

  4. Cend. with a period terminates the program. A semicolon after end is used to close blocks within the program (like procedure bodies), but the final end of the program requires a period.

  5. BWriteLn outputs the specified values and then moves the cursor to the next line. Write outputs the values but leaves the cursor on the same line.

  6. B — Pascal uses single quotes for string literals. Double quotes are not valid string delimiters in Pascal.

  7. B — The uses clause imports units (pre-compiled library modules) that provide additional procedures, functions, types, and constants.

  8. D/* */ is the C-style comment syntax. Pascal uses { }, (* *), or //.

  9. B — PATH lists the directories that the operating system searches when you type a command. If the Free Pascal bin directory is not in PATH, typing fpc will produce a "command not found" error.

  10. C.pas is the standard file extension for Pascal source code.

  11. B — Free Pascal produces .o (object) files as intermediate compilation output.

  12. B — The compiler catches type errors during compilation and refuses to produce an executable. This is one of the key advantages of a compiled, statically-typed language.

  13. CMyProgram is a valid identifier (starts with a letter, contains only letters). Option A has a space (invalid in identifiers). Option B starts with a digit (invalid). Option D uses incorrect syntax.

  14. C — F9 compiles and runs the current project in Lazarus.

  15. D — A Free Pascal executable is a standalone native binary. It needs only the operating system to run — no compiler, IDE, or runtime needs to be installed on the target machine.

  16. BReadLn; waits for the user to press Enter. Without it, the terminal window closes immediately when the program finishes, and you cannot see the output.

  17. B — A compiled language translates the entire source code into machine code before any execution begins. This is in contrast to interpreted languages, which translate and execute code line by line.

  18. B — The error message says "Identifier not found" for WriteLin. The correct name is WriteLn (short for "Write Line"). The numbers (5,12) indicate line 5, column 12 — exactly where the misspelled identifier appears.