ITPEC FE Morning April 2019 Question 8

Source exam: ITPEC FE Morning April 2019Topic: Basic Theory & Math

ITPEC FE Morning April 2019 — Question 8 of 80

String Concatenation via Character Arrays — copying two character arrays X (length m) and Y (length n) into a single array Z.

The algorithm uses two sequential loops:

  • Loop 1 (k: 1 to m): copies each character of X into the beginning of Z → X(k) → Z(k)
  • Loop 2 (k: 1 to n): copies each character of Y into Z starting after X → Y(k) → Z(m+k)

The key insight is the offset: Y's characters must start at position m + 1 in Z, so the index is m + k where k runs from 1 to n.

Why not others:
- (b) Uses Z(n+k) in B — offsets by n (Y's own length) instead of m (X's length), placing Y in the wrong position

- (c) Swaps the source arrays — copies Y first in Loop 1 and X in Loop 2

- (d) Same swap as (c), and also uses Z(n+k) instead of Z(m+k)

Key rule: When concatenating arrays, the second array's offset in the result equals the length of the first array.

AI-generated — may contain errors

The original exam layout is preserved in the image so diagrams, formulas, tables, and code remain accurate.

This question comes from an official ITPEC past paper. ITPEC Practice is an independent study tool and is not affiliated with ITPEC. See the official FE past-paper collection or Report an issue.