A programmer is creating a simple program that will keep track of the score in a children's game. The score starts at zero and increases as points are earned. Which of the following should the programmer use to store the score?
A variable is the correct choice for storing the score because variables allow for the stored data to be modified or updated while the program runs. Since the score changes throughout the game, a variable's mutable nature makes it ideal for this purpose. Constants cannot change once set, and functions are not storage containers but rather blocks of code designed to perform specific tasks. Therefore, while functions might be used to increase the score variable, they are not where you would store the score itself.
Ask Bash
Bash is our AI bot, trained to help you pass your exam. AI Generated Content may display inaccurate information, always double-check anything important.
What is a variable in programming?
Open an interactive chat with Bash
Why can't a constant be used to store the score in this case?
Open an interactive chat with Bash
What are the differences between a function and a variable?