Self-Assessment Quiz: Setting Up

Twenty questions to confirm the toolchain and its concepts have stuck before you move on to real programming in Chapter 3. Aim for 16 or more. Answers and a topic map are at the end — try the whole quiz first, and for the "what does this print?" items, work them out by hand before checking.


Question 1

On a Debian or Ubuntu system, which command installs the Fortran compiler this book uses? - A. sudo apt install fortran - B. sudo apt install gfortran - C. sudo apt install gcc - D. sudo apt install build-essential

Question 2

Which command confirms that gfortran is installed and reports its version? - A. gfortran --check - B. gfortran --version - C. gfortran -v hello.f90 - D. which fortran

Question 3

This book targets which minimum gfortran version as its baseline? - A. gfortran 4 - B. gfortran 7 - C. gfortran 10 - D. gfortran 20

Question 4

A source file named sim.f90 is treated by the compiler as: - A. fixed-form source - B. free-form source - C. a C source file - D. a header file

Question 5

Which statement prints its text flush against the left margin, with no leading blank? - A. print *, "hi" - B. write(*,*) "hi" - C. print '(a)', "hi" - D. All of them add a leading blank

Question 6

The correct order of the cycle that turns source into a running result is: - A. link → compile → run - B. compile → link → run - C. run → compile → link - D. compile → run → link

Question 7

The -c flag tells gfortran to: - A. compile and immediately run the program - B. stop after producing an object file, without linking - C. check the code for bugs only - D. clean up intermediate files

Question 8

A build that fails with undefined reference to 'my_routine_' failed at which stage? - A. the compile stage - B. the link stage - C. the run stage - D. the install stage

Question 9

The job of the linker is to: - A. translate source text into machine instructions - B. combine object files and libraries into a complete executable, resolving references - C. check that variables are declared - D. optimize loops for speed

Question 10

Which flag inserts run-time checks, most valuably for array bounds, and therefore belongs in a development build? - A. -O2 - B. -std=f2018 - C. -fcheck=all - D. -o

Question 11

Which flag asks the compiler to optimize the generated code for speed? - A. -g - B. -O2 - C. -Wall - D. -c

Question 12

Which flag holds your code to the 2018 ISO standard and warns when it uses non-standard extensions? - A. -Wall - B. -std=f2018 - C. -fcheck=all - D. -g

Question 13

True or false, with one sentence of justification: "It is fine to report a program's timing from a build compiled with -fcheck=all."

Question 14

True or false, with one sentence of justification: "A compiler warning halts the build the same way an error does."

Question 15

In free-form source, a statement too long for one line is continued by ending the line with: - A. a semicolon ; - B. a backslash \ - C. an ampersand & - D. three dots ...

Question 16

In free-form source, a comment is introduced by: - A. // - B. # - C. C in column one - D. !

Question 17

Without implicit none, an undeclared variable named n_iter would be given which type by Fortran's implicit typing rule? - A. real - B. integer - C. character - D. logical

Question 18

The essential benefit of implicit none is that it: - A. makes programs run faster - B. turns a mistyped variable name from a silent wrong answer into a compile-time error - C. reduces the size of the executable - D. allows variables to change type at run time

Question 19

What does this program print?

program q19
  use, intrinsic :: iso_fortran_env, only: dp => real64
  implicit none
  real(dp) :: a, b
  a = 6.0_dp
  b = 4.0_dp
  print '(a, f0.1)', 'mean = ', (a + b) / 2.0_dp
end program q19
  • A. mean = 5.0
  • B. mean = 5
  • C. mean = 10.0
  • D. mean = 2.5

Question 20

Where must the implicit none statement appear? - A. only in the main program, never in procedures - B. at the very end of each program unit - C. immediately after the opening line of each program unit, before the declarations - D. anywhere in the file


Answer Key

Q Ans Why
1 B The package is gfortran; gcc/build-essential do not include it.
2 B gfortran --version prints the version banner.
3 C The baseline is gfortran 10+ (full Fortran 2018 support).
4 B A .f90 extension signals free-form source.
5 C print '(a)' adds no leading blank; print * (and write(*,*)) may.
6 B Source is compiled to an object, objects are linked to an executable, then run.
7 B -c compiles only, leaving an object file (.o).
8 B "undefined reference" is a linker error — the symbol's definition was not found.
9 B The linker resolves references and combines objects and libraries into an executable.
10 C -fcheck=all inserts run-time checks (bounds, etc.); a development flag.
11 B -O2 turns on the standard optimization suite.
12 B -std=f2018 enforces the 2018 standard.
13 False -fcheck=all adds run-time overhead, so its timings are not representative — measure with -O2, checks off.
14 False A warning does not stop the build; only an error does. (You should still fix warnings.)
15 C Free-form continuation is a trailing ampersand &.
16 D Free-form comments begin with !; C-in-column-one is the fixed-form convention.
17 B n_iter begins with n, which falls in the in integer range.
18 B It converts silent typo-into-new-variable bugs into compile-time errors.
19 A (6.0 + 4.0)/2.0 = 5.0; f0.1 prints 5.0 with no leading blank.
20 C It goes right after the program/module/subroutine/function line, before declarations.

Topics to review by question

  • Q1–3 → §2.1 (installing and verifying gfortran).
  • Q4–5, 15–16 → §2.2 and §2.5 (source form; print; free-form conventions).
  • Q6–9 → §2.3 (the compile–link–run cycle; object files, the linker, and the two kinds of error).
  • Q10–14 → §2.4 (the five early flags and the two build profiles).
  • Q17–18, 20 → §2.6 (implicit none and implicit typing).
  • Q19 → §2.7 and §2.2 (a first computation; reading print '(a)' output by hand).

Scored below 16? Reread the flagged sections and — more important — actually compile and run the programs in Questions 7, 8, 19, and 20 for yourself. This chapter is learned at the keyboard, not on paper.