Interview Review & Mastery Checklist

Review the whole course through interview-style questions and tricky-output puzzles (bounds, mod/rem, attributes, subtypes, parameter passing, 'Image), a topic checklist from beginner to advanced, and a roadmap for continuing with SPARK, embedded Ada and open-source projects.

This final lesson condenses the course into the questions interviewers and code reviewers actually ask, with a program whose output you should be able to predict line by line. Use the checklist to find topics to revisit.

Predict the Output

Ten classic questions: string bounds that don't start at 1, mod vs rem, 'Succ/'Pos, subtypes and 'Base, precedence, in out parameters, concatenation, Boolean ordering, 'Image spacing and 'Reduce. GNAT notes that Q4's comparison is always True. Output: Q1 S'First = 5, S (6) = b Q2 (-7) / 2 =-3, (-7) mod 3 = 2, (-7) rem 3 =-1 Q3 Color'Succ (Red) = GREEN, Color'Pos (Blue) = 2 Q4 Tiny'Last = 3, Tiny'Base'Last >= 10: TRUE Q5 2 ** 10 = 1024, 10 / 3 * 3 = 9 Q6 after Bump (X, X): X = 10 Q7 "Ada" & 'X' & "!" = AdaX! Q8 Boolean'Pos (True) = 1, False < True: TRUE Q9 Integer'Image (-5) = [-5], Integer'Image (5) = [ 5] Q10 A'Length = 3, sum = 21

• S (5 .. 7) — S'First = 5; always use 'Range. • (-7) mod 3 = 2, (-7) rem 3 = -1; / truncates toward zero. • 10 / 3 * 3 = 9 (integer division first). • 'Image adds a leading space for non-negative numbers.

with Ada.Text_IO; use Ada.Text_IO;

procedure L70_Interview is
   type Small is range 1 .. 10;
   subtype Tiny is Small range 1 .. 3;
   type Color is (Red, Green, Blue);
   S : constant String (5 .. 7) := "abc";
   X : Integer := 5;

   procedure Bump (V : in out Integer; W : Integer) is
   begin
      V := V + W;
   end Bump;
begin
   Put_Line ("Q1  S'First =" & Integer'Image (S'First) & ", S (6) = " & S (6));
   Put_Line ("Q2  (-7) / 2 =" & Integer'Image ((-7) / 2) & ", (-7) mod 3 =" & Integer'Image ((-7) mod 3)
             & ", (-7) rem 3 =" & Integer'Image ((-7) rem 3));
   Put_Line ("Q3  Color'Succ (Red) = " & Color'Image (Color'Succ (Red))
             & ", Color'Pos (Blue) =" & Integer'Image (Color'Pos (Blue)));
   Put_Line ("Q4  Tiny'Last =" & Small'Image (Tiny'Last) & ", Tiny'Base'Last >= 10: "
             & Boolean'Image (Tiny'Base'Last >= 10));
   Put_Line ("Q5  2 ** 10 =" & Integer'Image (2 ** 10) & ", 10 / 3 * 3 =" & Integer'Image (10 / 3 * 3));
   Bump (X, X);
   Put_Line ("Q6  after Bump (X, X): X =" & Integer'Image (X));
   Put_Line ("Q7  ""Ada"" & 'X' & ""!"" = " & "Ada" & 'X' & "!");
   Put_Line ("Q8  Boolean'Pos (True) =" & Integer'Image (Boolean'Pos (True))
 
…

Frequently Asked Interview Questions

Type vs subtype? A type is a distinct set of values and operations; a subtype adds a constraint and stays compatible. Why is Ada safe? Strong typing, range/index/overflow checks, no implicit conversions, explicit pointers with accessibility rules, contracts, and structured concurrency. Procedures vs functions? Statements vs value-returning expressions. Parameter modes? in/out/in out; scalars by copy, tagged/limited by reference. Private vs limited private? Limited also forbids assignment and predefined equality. When does a call dispatch? When the controlling operand is class-wide. Generics vs templates? Ada generics are checked against their formal contract once. Task vs protected object? Active thread vs passive, mutually exclusive shared data with barriers. Ravenscar? A restricted, analysable tasking profile. What is SPARK? A provable Ada subset with GNATprove. What is elaboration? Initialization of library units before main. How are exceptions from declarations handled? They propagate to the enclosing scope.

• Be ready to explain: typing, checks, modes, private/limited, dispatching, generics, tasking, Ravenscar, SPARK, elaboration, exceptions.

Mastery Checklist and Next Steps

Revisit any line you can't explain with an example.

Next steps: learn.adacore.com (interactive courses on Ada, SPARK and embedded Ada), the Ada Reference Manual (ada-auth.org) and its Rationale documents, Alire's crate index for real-world libraries, programming Ada on microcontrollers (ARM Cortex-M boards with GNAT's embedded runtimes), and contributing to open-source Ada projects. Practise by rewriting a small tool you know in Ada, then proving part of it in SPARK.

• learn.adacore.com, the ARM (Ada Reference Manual), Alire crates. • Embedded Ada on Cortex-M; SPARK proofs. • Rewrite a familiar tool in Ada; prove a component.

for I in 1.. S'Length loop... S (I) -- S'First = 5 for I in S'Range loop... S (I)

Slices and explicit bounds don't start at 1.

-- expecting 10 / 3 * 3 = 10 -- integer division truncates first: 3 * 3 = 9

Use Float or reorder operations when exactness matters.

-- answering 'Ada is only for the military' -- aviation, rail, space, medical, automotive, security, and general software

Ada's use is broad wherever reliability matters.

S: String (5.. 7):= "abc"; what is S (6)? A. a B. b C. c D. Constraint_Error B. b (verified).

What is (-7) mod 3? A. -1 B. 2 C. 1 D. -2 B. 2 (verified).

After 'Bump (X, X)' with X = 5 (V : in out, W : in, V := V + W), what is X? A. 5 B. 10 C. 15 D. Undefined

B. 10 (verified; scalars are passed by copy, so W keeps the entry value 5).

What is Integer'Image (5)? A. "5" B. " 5" C. "+5" D. "05" B. " 5" (verified).

Predict every line of the interview program before revealing the answer.

Real output: Q1 S'First = 5, S (6) = b Q2 (-7) / 2 =-3, (-7) mod 3 = 2, (-7) rem 3 =-1 Q3 Color'Succ (Red) = GREEN, Color'Pos (Blue) = 2 Q4 Tiny'Last = 3, Tiny'Base'Last >= 10: TRUE Q5 2 ** 10 = 1024, 10 / 3 * 3 = 9 Q6 after Bump (X, X): X = 10 Q7 "Ada" & 'X' & "!" = AdaX! Q8 Boolean'Pos (True) = 1, False < True: TRUE Q9 Integer'Image (-5) = [-5], Integer'Image (5) = [ 5] Q10 A'Length = 3, sum = 21

Beginner      program structure, types, subtypes, attributes, control flow, subprograms, arrays, strings, records
Intermediate  packages, private/limited types, child units, access types, exceptions, contracts, containers, I/O
Advanced      OOP (tagged/interfaces/controlled), generics & formal packages, tasking, protected objects, select,
              real-time & Ravenscar, representation clauses, C interfacing, streams, SPARK, high-integrity practice
Tooling       gnatmake/gprbuild/Alire, gdb, tracebacks, testing, style checks
with Ada.Text_IO; use Ada.Text_IO;

procedure L70_Interview is
   type Small is range 1 .. 10;
   subtype Tiny is Small range 1 .. 3;
   type Color is (Red, Green, Blue);
   S : constant String (5 .. 7) := "abc";
   X : Integer := 5;

   procedure Bump (V : in out Integer; W : Integer) is
   begin
      V := V + W;
   end Bump;
begin
   Put_Line ("Q1  S'First =" & Integer'Image (S'First) & ", S (6) = " & S (6));
   Put_Line ("Q2  (-7) / 2 =" & Integer'Image ((-7) / 2) & ", (-7) mod 3 =" & Integer'Image ((-7) mod 3)
             & ", (-7) rem 3 =" & Integer'Image ((-7) rem 3));
   Put_Line ("Q3  Color'Succ (Red) = " & Color'Image (Color'Succ (Red))
             & ", Color'Pos (Blue) =" & Integer'Image (Color'Pos (Blue)));
   Put_Line ("Q4  Tiny'Last =" & Small'Image (Tiny'Last) & ", Tiny'Base'Last >= 10: "
             & Boolean'Image (Tiny'Base'Last >= 10));
   Put_Line ("Q5  2 ** 10 =" & Integer'Image (2 ** 10) & ", 10 / 3 * 3 =" & Integer'Image (10 / 3 * 3));
   Bump (X, X);
   Put_Line ("Q6  after Bump (X, X): X =" & Integer'Image (X));
   Put_Line ("Q7  ""Ada"" & 'X' & ""!"" = " & "Ada" & 'X' & "!");
   Put_Line ("Q8  Boolean'Pos (True) =" & Integer'Image (Boolean'Pos (True))
 
…