Difference Between Keyword and Identifier


Every programming language has keywords and identifiers. Both keywords and identifiers can be processed by a compiler, however they are quite different from each other. The basic difference between the two is that keywords are the reserve words which are predefined and have a special meaning in the language, whereas an identifier is a unique name assigned to a variable, function, class, etc.

Read this article to learn more about keywords and identifiers and how they are different from each other.

What is a Keyword?

Keywords are reserved words that have a special meaning in a programming language. Therefore, we cannot use a keyword as a name of an identifier or any other program entity.

Every keyword in a programming language has a distinct meaning which can be interpreted by the compiler of the language to perform a specific function.

Examples of keywords include 'int', 'float', 'char', etc. All these are the data types in programming languages that tell the compiler about the data type of a variable.

What is an Identifier?

In a program, the name given to an entity of a program is known as an identifier. An identifier is always unique, i.e., once a word is given to an entity as a name, the same word cannot be used to name any other entity. In simple words, the names of variables, functions, labels, and other user-defined entities are termed as identifiers.

The important point to note about identifiers is that a keyword cannot be used as an identifier.

Now, let us discuss the differences between keyword and identifier.

Difference between Keyword and Identifier

The following are the important differences between keyword and identifier −

S.No.

Keyword

Identifier

1.

They define a specific kind of entity.

They are used to name a variable, a function, a class, a structure, a union.

2.

It always starts with a lower case letter.

It can be upper case or lower case.

3.

They are pre-defined words that are reserved to work with programs.

They can consist of alphabets, digits, and underscores.

4.

They can't be used anywhere else.

It is created to give a unique name to an entity.

5.

It can only contain alphabetical characters.

There is no punctuation or special symbol, except the underscore.

6.

It helps identify a specific property which exists within a language.

It helps locate the name of the entity which is defined along with a keyword.

7.

There are special symbols or punctuations used.

All of them are not variables.

Conclusion

The most significant difference that you should note here is that keywords always start with lowercase letters, while an identifier can start with uppercase or lowercase letters.

Updated on: 21-Feb-2023

4K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements