CompTIA Tech+ (FC0-U71)Software Development ConceptsEasy

A programmer is designing a simple game where the player's inventory needs to store multiple items, such as 'Sword', 'Shield', and 'Potion'. Which data structure is most suitable for holding this collection of items?

  1. AInteger
  2. BArray
  3. CBoolean
  4. DSingle variable
Show answer & explanation

Correct answer: B. Array

An array is the most suitable data structure for storing a collection of multiple items, like a player's inventory. It allows for ordered storage and easy access to individual elements.

Why the other options are wrong

  • A. An Integer stores whole numbers and cannot hold item names.
  • C. A Boolean stores true/false values and is not suitable for storing item names.
  • D. A single variable can only hold one item at a time, not a collection.

Array Data Structure

A data structure consisting of a collection of elements (values or variables), each identified by at least one array index or key. Arrays store multiple items of the same or different data types.

  • Stores multiple items in a single structure.
  • Elements are typically accessed via an index (e.g., 0, 1, 2).
  • Useful for lists, collections, and sequences of data.

Memory trick: An 'array' of items is like an 'array' of boxes in a row.

More Software Development Concepts questions