CompTIA Tech+ (FC0-U71)Software Development ConceptsEasy

A developer is writing a program that needs to store a user's chosen difficulty level for a game, which can be 'Easy', 'Medium', or 'Hard'. Which of the following data types would be most appropriate for this variable?

  1. ABoolean
  2. BInteger
  3. CString
  4. DFloat
Show answer & explanation

Correct answer: C. String

The difficulty levels 'Easy', 'Medium', and 'Hard' are textual values. The String data type is used to store sequences of characters, which is perfect for these descriptive labels.

Why the other options are wrong

  • A. Boolean stores only true/false values.
  • B. Integer stores whole numbers.
  • D. Float stores decimal numbers.

String Data Type

A String is a sequence of characters, such as letters, numbers, symbols, and spaces, enclosed in quotes. It is used to represent text.

  • Used for textual data
  • Can contain letters, numbers, symbols
  • Immutable in many languages

Memory trick: Text options? String is the strong choice!

More Software Development Concepts questions