CompTIA IT Fundamentals Exam: Answer Key

Global Variable Data Types | CompTIA IT Fundamentals

Question

A global variable called 'age' will be created in a program and incremented through the use of a function.

Which of the following data types should be defined with the age variable?

Answers

Explanations

Click on the arrows to vote for the correct answer

A. B. C. D.

A.

In this scenario, the global variable age will be incremented through the use of a function. To determine the data type that should be defined with the age variable, we need to consider the type of data that will be stored in the variable.

A. Integer: An integer is a whole number that can be positive, negative, or zero. Integers are commonly used for counting, indexing, and performing arithmetic operations. Since age is typically measured in whole numbers, an integer data type is a suitable choice for the age variable.

B. Float: A float is a decimal number that can represent fractions or numbers with decimal places. Floats are commonly used in scientific and mathematical applications that require high precision. However, since age is typically measured in whole numbers, a float data type is not necessary for the age variable.

C. Double: A double is similar to a float in that it represents decimal numbers with high precision. However, a double can represent larger numbers than a float. Since age is typically a small whole number, a double data type is not necessary for the age variable.

D. String: A string is a sequence of characters that represents text. Strings are commonly used to store names, addresses, and other textual data. However, since age is a numerical value that will be incremented through a function, a string data type is not suitable for the age variable.

In conclusion, the most suitable data type for the age variable is an integer data type.