Self-Assessment Quiz: Variables, Types, and Arithmetic

Twenty questions to confirm you can declare, compute, and print numbers correctly before moving on to control flow. Aim for 16 or more. Several are "what does this print?" — predict, then reason it out. The answer key and a topic map are at the end; try the whole quiz first.


Question 1

Which intrinsic type should hold the number of grid cells along one edge of the plate? - A. real - B. integer - C. logical - D. character

Question 2

A default (single-precision) real carries roughly how many significant decimal digits? - A. About 3 - B. About 7 - C. About 15 - D. About 30

Question 3

selected_real_kind(15, 307) requests a real kind with: - A. Exactly 15 bytes of storage - B. At least 15 significant digits and a range to at least $10^{307}$ - C. A kind number equal to 15 - D. 15 bits of precision

Question 4

In Fortran, the expression 1 / 2 evaluates to: - A. 0.5 - B. 0 - C. 1 - D. A compile error

Question 5

What is the value of 7 / 2 in Fortran? - A. 3.5 - B. 4 - C. 3 - D. 3.0

Question 6

mod(-7, 3) and modulo(-7, 3) evaluate, respectively, to: - A. 2 and 2 - B. -1 and -1 - C. -1 and 2 - D. 2 and -1

Question 7

x is real(dp) and a, b are integers. Which line assigns the true real quotient of a and b to x? - A. x = a / b - B. x = real(a, dp) / real(b, dp) - C. x = int(a) / int(b) - D. x = mod(a, b)

Question 8

Writing a real literal as 0.5_dp rather than 0.5 matters because: - A. 0.5_dp is a double-precision constant; plain 0.5 is a single-precision constant, rounded to ~7 digits - B. The two are identical in every way - C. 0.5_dp is an integer - D. _dp makes the literal a parameter

Question 9

Attempting to assign a new value to a variable declared with the parameter attribute results in: - A. A run-time crash - B. A silent no-op - C. A compile-time error - D. The value changing normally

Question 10

Fortran's intrinsic sin, cos, and tan expect their argument in: - A. Degrees - B. Radians - C. Gradians - D. Whatever unit you last used

Question 11

The difference between mod and modulo is that: - A. mod is for reals, modulo for integers - B. mod takes the sign of the dividend; modulo takes the sign of the divisor - C. They are identical - D. modulo is not standard Fortran

Question 12

use, intrinsic :: iso_fortran_env, only: real64 gives you a kind parameter that is: - A. Single precision (32-bit) - B. Double precision (64-bit) - C. An integer counter - D. A character length

Question 13

For complex :: z = (3.0, 4.0), the intrinsic abs(z) returns: - A. 3.0 - B. 4.0 - C. 5.0 (the modulus $\sqrt{3^2 + 4^2}$) - D. 7.0

Question 14

What does print '(f6.2)', 3.14159 output? (Show spacing.) - A. 3.14 - B. 3.14 - C. 3.141590 - D. ******

Question 15

Why does this book request precision with selected_real_kind instead of writing real(8)? - A. real(8) is illegal Fortran - B. The kind number 8 is compiler-specific, so real(8) is not portable; selected_real_kind states the requirement - C. real(8) is slower - D. There is no difference

Question 16

Exponentiation associates right-to-left, so 2 ** 3 ** 2 equals: - A. 64 - B. 512 - C. 36 - D. 12

Question 17

x is real(dp). What does this print?

x = 5 / 2
print '(f6.3)', x
  • A. 2.500
  • B. 2.000
  • C. 0.400
  • D. 3.000

Question 18

True or false: writing real(dp) :: g = 9.81 stores the full double-precision value of 9.81 in g.

Question 19

What does print '(es12.4)', 1.0e-4_dp output? (Show spacing.) - A. 1.0000E-04 - B. 0.0001 - C. 1.0E-4 - D. 0.0001E+00

Question 20

What is the value and type of 5.0_dp / 2? - A. 2 (integer) - B. 2.5_dp (real(dp)) - C. 2.5 (default real) - D. A compile error


Answer Key

Q Ans Why
1 B A cell count is a whole number → integer.
2 B Default real ≈ 6–7 significant digits.
3 B selected_real_kind(p, r) asks for ≥ p digits and range ≥ $10^{r}$.
4 B Both operands are integers → integer division → 0.
5 C 7/2 truncates toward zero → 3.
6 C mod follows the dividend (−7 → −1); modulo follows the divisor (3 → 2).
7 B Convert at least one operand to real before the division.
8 A 0.5 is a single-precision literal; 0.5_dp is double.
9 C A parameter is fixed at compile time; reassigning it fails to compile.
10 B Trig intrinsics use radians; convert degrees with * pi / 180.
11 B The sign rule is the whole difference; they agree for positive arguments.
12 B real64 is the 64-bit (double) kind.
13 C For a complex number, abs is the modulus, here $\sqrt{9+16}=5$.
14 B f6.2 rounds to 3.14 and right-justifies in 6 → two leading spaces.
15 B Kind numbers are compiler-specific; request the requirement, not the size.
16 B 2**(3**2) = 2**9 = 512.
17 B 5/2 is integer 2, then widened to 2.0 → prints 2.000.
18 False 9.81 is a single-precision literal; write 9.81_dp for the full double value.
19 A es12.4 → mantissa 1.0000 × E-04, right-justified in 12.
20 B The integer 2 is promoted to real(dp); the result is 2.5_dp.

Topics to review by question

  • Q1, Q13 → §3.1 (the intrinsic types; complex).
  • Q2, Q3, Q8, Q12, Q15, Q18 → §3.2 (kinds, dp, portable precision).
  • Q4, Q5, Q7, Q17, Q20 → §3.3–§3.4 (mixed-mode and the integer-division trap).
  • Q6, Q10, Q11, Q16 → §3.5 (intrinsic math functions; mod vs modulo).
  • Q9 → §3.6 (parameter).
  • Q14, Q19 → §3.7 (formatted output).

Scored below 16? The two sections that most reward a reread are §3.2 (precision) and §3.4 (integer division) — those are the ones whose mistakes are silent, and silent mistakes are the expensive ones.