What is the Difference Between Identifier and Variable?

🆚 Go to Comparative Table 🆚

The main difference between an identifier and a variable lies in their purpose and function within a computer program:

  • Identifier: An identifier is a unique name assigned to an entity in a program, such as a variable, function, class, structure, or constant. It is used to identify the entity and distinguish it from others in the program. Identifiers cannot have the same name, and they should not resemble keywords, as keywords are predefined and used for special purposes.
  • Variable: A variable is a name assigned to a memory location that stores a value. Variables are used to hold data and can be changed during the program's execution. The value of a variable can be real, Char, String, Int, Float, Double, Unsigned, etc..

In summary:

  • Identifiers are used to name entities in a program, such as variables, functions, classes, structures, or constants.
  • Variables are used to store data in memory locations, and their values can change during the program's execution.

Comparative Table: Identifier vs Variable

The difference between an identifier and a variable can be summarized as follows:

Identifier Variable
Used to name a variable, function, class, structure, or union Used to give a name to a memory location that holds a value
Assigns a unique name to an entity Assigns a unique name to a specific memory location
All identifiers are not variables, but all variable names are identifiers Cannot exceed a certain number of characters

In other words, an identifier is used to assign a name to an entity like a variable, function, or class, while a variable is used to assign a name to a memory location where a value is stored.