CompTIA Tech+ (FC0-U71)Software Development ConceptsEasy

A junior developer is writing a script to store a user's age. Which of the following data types would be most appropriate for this variable?

  1. ABoolean
  2. BString
  3. CFloat
  4. DInteger
Show answer & explanation

Correct answer: D. Integer

An integer is the most appropriate data type for storing a user's age because age is typically represented as a whole number without decimal points. Using a string would require conversion for mathematical operations, while boolean and float are unsuitable for whole number age representation.

Why the other options are wrong

  • A. Booleans represent true/false values, which is not applicable for storing age.
  • B. Strings are for text and would require conversion for mathematical operations, making them less efficient for age.
  • C. Floats are for numbers with decimal points, which is generally not how age is represented.

Integer Data Type

A data type used to store whole numbers (positive, negative, or zero) without any fractional or decimal components.

  • Represents whole numbers.
  • Commonly used for counts, ages, IDs.
  • Does not store decimal values.

Memory trick: Integers are for 'int'act whole numbers.

More Software Development Concepts questions