Key Difference – Identifier vs Keyword
There are various concepts such as variables, functions, etc. in programming. A variable is a memory location to store data. A function is a block of statements to perform a specific task. When writing the program, it is important to give meaningful names as it improves code readability. Therefore, the programmer can create names to identify them. They are known as identifiers. An identifier is a user defined name given to a variable, function, array or class. There is also a set of words provided by the programming language having specific meanings. They are known as keywords. Keywords belong to the language, and each have particular tasks. These keywords cannot be used as identifier names. This article discusses the difference between an identifier and a keyword. The key difference between identifier and keyword is that, an identifier is a user defines name for variable, function, class while a keyword is a reserved word provided by the programming language.
1. Overview and Key Difference
2. What is an Identifier
3. What is a Keyword
4. Similarities Between Identifier and Keyword
5. Side by Side Comparison – Identifier vs Keyword in Tabular Form
What is an Identifier?
A name created by the programmer to define a variable, function or class is known as an identifier. The identifiers are used to identify these entities uniquely. It is important to give meaningful names to the identifiers to make the code easily readable. It will also help other programmers to identify what the program is about.
There are certain rules when creating identifiers. Identifiers are permitted only to use alphabetical characters, digits and underscore. It is not recommended to start an identifier with a digit. When there is a statement such as int number = 4; the number is the identifier. The programmer can print the value of that variable using the name ‘number’. Most programming languages support case sensitivity. Therefore, the variable name ‘area’ is different from ‘AREA’.
For a function to calculate the sum of two numbers, the name can be calculate_sum (). Other valid identifiers are employee_salary, student_id and number. When creating a class, the programmer can use a meaning identifier that describes the attributes and methods. e.g. class Student, class Employee, class Rectangle etc. Likewise, the programmer can create identifiers according to the program.
What is a Keyword?
The keywords are provided by the programming language for a specific task. They have special meanings. Keywords cannot be used as identifiers. The keywords are also known as reserved words. When there is a statement in the program as int number = 2; it means that the number is a variable which contains the value 2. The int is a keyword. It informs the compiler that the memory location can store an integer value. When there is a statement as float area; the float is a keyword and area is an identifier. The area variable can hold a floating-point value.
In programming, there are situations to repeat a sequence of statements. The for loop and while loop is used for iterative tasks. For decision, if/else can be used. If the logic is true, then the statements inside the if block will execute. Otherwise, the statements inside the else block will execute. These are a few examples of keywords common to many programming languages. The keywords cannot be used as names for the program variables or other user defined program elements.
What is the Similarity Between Identifiers and Keyword?
- Both identifier and keywords are used in programming.
What is the Difference Between Identifier and Keyword?
Identifier vs Keyword
|An identifier is a user defined name for a variable, function, class.||A keyword is a reserved word provided by the programming language.|
|An identifier can consist of alphabetical characters, digits and underscores.||A keyword contains only alphabetical characters.|
|An identifier can be in upper case or lower case.||A keyword should be in lower case.|
Summary – Identifier vs Keyword
Identifier and keyword are common terms used in programming. When there is a statement in the as int mark; the mark is an identifier and int is the keyword. An identifier is created by the programmer while the keyword is used by the compiler for a specific action. This article discussed the difference between an identifier and a keyword. The difference between identifier and keyword is that an identifier is a user defines a name for variable, function, class while a keyword is a reserved word provided by the programming language.
Download the PDF of Identifier vs Keyword
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 Keyword