Difference Between Identifier and Variable

August 2022 · 5 minute read

Key Difference – Identifier vs Variable
 

A programming language is designed to process certain kind of data and to provide useful information. The data can be numbers, characters, strings, etc. A program is a set of instructions written in a specific programming language to provide instructions to a computer. The computer process data according to the instructions. When manipulating data, it is necessary to store them. A variable is a storage area capable of holding a value. The variables have names to identify them. Not just variables, functions, classes, etc. also have names, which are called identifiers. Identifiers are created by the programmer. Identifier and variable are two common terms in programming. The key difference between identifier and variable is that an identifier is a name given to a variable, function, array, class or structure while a variable is a name given to a memory location that can hold a value.

CONTENTS

1. Overview and Key Difference
2. What is an Identifier
3. What is a Variable
4. Similarities Between Identifier and Variable
5. Side by Side Comparison – Identifier vs Variable in Tabular Form
6. Summary

What is an Identifier?

An identifier refers to a name of a variable, function, array, class or structure. The identifiers are created by programmers.  It is important to use unique names for identifiers because they are identified in the execution of the program. Programming languages follow a specific set of rules to name identifiers. Most of the time, only alphabetical characters (A to Z or a to z), underscore (_) and digits (0 to 9) are used for valid identifiers. Generally, the first character of the identifier can be an underscore or a letter, and should not be a digit.

In programming, if there is a statement as int number; it means that there is a variable called number which can hold an integer value. The word ‘number’ is an identifier.  When there is a statement as double area; it means that there is a variable called area that can hold a double value. The ‘area’ is a valid identifier.  Some examples of valid identifiers are age, salary, studentNo, amount and _empNo. Some examples of invalid identifiers are 123abc, -studentno. The identifier 123abc starts with a digit. So, it is invalid. The identifier -studentno starts with a character other than alphabetical character or underscore.

Difference Between Identifier and Variable

Figure 01: Identifier and Variable

Most programming languages are case sensitive. Therefore, lowercase and uppercase letters are distinct. The identifier amount and AMOUNT are two separate identifiers even they have the same name. It is important to use meaningful names for identifiers because it improves code readability. Meaningful identifiers also make the program easy to understand.

What is a Variable?

In programming, it is required to store data. Computations are carried on the stored data. These data should be stored in a memory location. A variable is a container or a storage area to hold data. A unique name or an identifier is given to variables to identify each storage area. Variable names represent the memory locations to store data. Each variable has a specific data type to store.

In the variable declaration, the variable name is specified, but there is no memory allocated for the variable. When there is a statement as int number; it means that the variable name is number and it can store an integer value. But does not set aside any memory for the variable number. Assigning an initial value for the variable is called initialization. When there is a statement as int number = 5; the variable number can store an integer value and it is initialized to 5.

What is the Similarity Between Identifier and Variable

What is the Difference Between Identifier and Variable?

Identifier vs Variable 

An identifier is a name given to a variable, function, array, class or structure.A variable is a name given to a memory location that can hold a value.
 Range
The range of identifiers is higher than variables.Variables names are identifiers.
Usage
An identifier is used to give a unique name to an entity.A variable is a unique name to identify a memory location.

Summary – Identifier vs Variable

In programming, there are so many concepts such as variables, functions, classes etc. The main purpose of each is to manipulate data correctly to solve computation problems. The variables, function, classes should be given appropriate names in order to identify them and to understand the program. Identifiers are the names given to them. The data is stored in memory, and these memory locations should be given names to identify them. This article discussed the difference between the identifier and a variable. The difference between identifier and variable is that an identifier is a name given to a variable, function, array, class or structure while a variable is a name given to a memory location that can hold a value.

Download the PDF of Identifier vs Variable

You can download the PDF version of this article and use it for offline purposes as per citation note. Please download the PDF version here: Difference Between Identifier and Variable

Reference:

1.tutorialspoint.com. “Java Basic Syntax.” The Point, Available here  

ncG1vNJzZmivp6x7pbXFn5yrnZ6YsqOx07CcnqZemLyue8OinZ%2Bdopq7pLGMm5ytr5Wau261w56lraGWnrKzecCnm2auo2LDor7ImpmlnV8%3D