Swapping two values with a temporary variable
Saves the value of Marks[Index] in Temp so it is not lost. Marks[Index] can then be overwritten, and Temp is copied into Marks[Index + 1] to finish the swap.
Understanding Swapping two values with a temporary variable in IGCSE Computer Science Paper 2
What it does: After Temp has saved Marks[Index], that element can be overwritten with the value from Marks[Index + 1] without losing data. Save the first value in Temp, copy the second into the first, then copy Temp into the second. Each value ends up in the other position.
Common mistakes: Temp must save Marks[Index], the value that is about to be overwritten. Saving Marks[Index+1] means the original Marks[Index] is lost. It should be Temp ← Marks[Index]. The second element is overwritten with Marks[1] when it should be Marks[1] that is overwritten with Marks[2]. Both elements would end up as 40. It should be Marks[1] ← Marks[2].
Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.
This module's key terms are also in a printable crossword (Modules 296–306) and word search (Modules 296–316).
Take this worksheet further — free with Cloodit
Each concept is reinforced from every angle — learned, then applied, then tested.
Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.
Over 100 of them, across seven natural biomes.
Turns their work into revision material ready for Flash Cards and Exam study.
Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.
Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.
Quick Questions
Match the Pairs
Key Term
Temp ← Marks[Index]Fill in the Blanks
Spot the Error
Student with a class code? Join your class →