CompTIA Tech+ (FC0-U71)Software Development ConceptsMedium

A junior developer is writing a program that needs to store a user's age, which will always be a whole number. Which of the following data types would be the most memory-efficient choice?

  1. AFloat
  2. BInteger
  3. CBoolean
  4. DString
Show answer & explanation

Correct answer: B. Integer

An integer data type is specifically designed to store whole numbers, making it the most appropriate and memory-efficient choice for an age value which is always a whole number. Other types would either use more memory or be unsuitable.

Why the other options are wrong

  • A. Float stores decimal numbers and uses more memory than an integer for whole numbers.
  • C. Boolean stores true/false values and cannot represent age.
  • D. String stores text and uses significantly more memory than an integer for a number.

Integer Data Type

An integer data type is used to store whole numbers (positive, negative, or zero) without any fractional components.

  • Represents non-decimal numbers.
  • Memory usage varies by language and specific integer type (e.g., short, int, long).
  • Efficient for counting and indexing.

Memory trick: Data types are like different-sized containers for your data.

More Software Development Concepts questions