What is the primary role of a variable in a computer program?

2025

What is the primary role of a variable in a computer program?

  1. A.

    Constant value used throughout the program

  2. B.

    A statement that prints messages

  3. C.

    A symbol used to calculate values

  4. D.

    A named area in memory used to store data

Attempted by 173 students.

Show answer & explanation

Correct answer: D

Instead of forcing programmers to remember raw memory addresses like 0x7fff5fbff710 to find a piece of data, programming languages use variables:

  1. Abstraction: A variable gives a human-readable identifier (a name, like userAge or totalPrice) to that specific memory location.

  2. Storage and Retrieval: When you write int score = 10;, the computer allocates a small block of memory, labels it score, and places the value 10 inside it. When you reference score later, the computer automatically goes back to that exact memory address to fetch the value.

  3. Dynamic Modification: Because it is variable, the program can overwrite the contents of that allocated memory address at any time (e.g., updating score = score + 5) without changing the name or location of the container itself.

Explore the full course: Rssb Senior Computer Instructor