What is the Difference Between Identifier and Keyword?

🆚 Go to Comparative Table 🆚

The main difference between an identifier and a keyword lies in their purpose and structure in programming languages. Here are the key differences between the two:

  • Keyword: Keywords are predefined and specific reserved words that hold special meaning in a programming language. They help in defining any statement in the program. Keywords are written in lowercase and cannot be used as identifiers. Examples of keywords include 'int', 'float', 'char', 'if', and 'while'.
  • Identifier: An identifier is a unique name generated by the programmer to define a variable, structure, class, or function. It can consist of alphabetical characters, digits, and underscores. The first character of an identifier can be an uppercase, lowercase letter, or underscore. Identifiers are used to locate the name of the entity that gets defined along with a keyword.

In summary, keywords are predefined words with special meanings, while identifiers are user-defined names for variables, functions, and other program elements. Keywords can only contain alphabetical characters and are written in lowercase, whereas identifiers can consist of alphabetic characters, digits, and underscores, and can be written in either lowercase or uppercase.

Comparative Table: Identifier vs Keyword

Here is a table comparing the differences between identifiers and keywords:

Feature Keyword Identifier
Definition Predefined words with fixed meanings in a language. Names for objects like databases, tables, or columns.
Case Should be in lowercase. Can be in uppercase or lowercase.
Characters Contains only alphabetic characters. Can consist of alphabetic characters, digits, and underscores.
Usage Helps to specify the type/kind of entity. Identifies the name of a particular entity.

Keywords are predefined words in a programming language that have specific meanings and are reserved for a particular purpose. They help specify the type or kind of entity and always start with a lowercase letter. On the other hand, identifiers are values used to define different programming items such as variables, integers, structures, and unions. They help identify the name of a particular entity and can have a mix of alphabetic characters, digits, and underscores.