Difference Between Identifier and Variable


An Identifier is a name assigned to an entity in a computer program so that it can be identified distinctly in the program during its execution. On the other hand, a variable is a name assigned to a memory location that stores a value. Read this article to learn more about identifiers and variables and how they are different from each other.

What is an Identifier?

Identifiers are used to name a variable, a function, a class, a structure, a union. In other words, an identifier is created to give a unique name to an entity. It can consist of alphabets, digits, and underscores, and can be written in uppercase or lowercase. There is no punctuation or special symbol, except the underscore in the declaration of an identifier.

An identifier can start with lowercase letters, uppercase letters, or an underscore. It helps to locate the name of the entity which is defined along with a keyword.

What is a Variable?

Variables are used to give a name to a memory location that holds a value. Hence, a variable is also an identifier. The names of variables are different which cannot be a keyword. Also, the value stored in a variable can be modified during the execution of the program.

In structured programming languages such as C, variables must be declared at the starting of the program. In object-oriented programming like C++, variables can be declared anywhere in the program.

According to the scope, there are three types of variables namely, local, global, and reference variables. Variables help to allot a unique name to a specific memory location.

Now, let us discuss the differences between identifier and variable in detail.

Difference between Identifier and Variable

The following table highlights all the important differences between identifier and variable −

S.No.

Identifier

Variable

1.

It is used to name a variable, a function, a class, a structure, a union.

It is used to give a name to a memory location that holds a value.

2.

Identifiers are created assign a name to an entity.

Variable is created to assign a unique name to a specific memory location.

3.

All identifiers are not variables.

All the variables names are identifiers.

4.

Identifier can take more number of characters.

Variable takes less number of characters.

Conclusion

The most significant difference is that an identifier is used to assign a name to an entity like a class, or a function, while a variable is used to assign a name to a memory location.

Updated on: 21-Feb-2023

12K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements