Difference Between Keyword and Identifier

Difference Between Keyword and Identifier

Keyword and Identifier – Every language has keywords and identifiers, which are only understood by its compiler. Keywords are predefined reserved words, which possess special meaning. Each keyword defines the “type” declared data. Keywords should not be used as identifiers. An identifier is a unique name given to a particular variable, function or label of class in the program. To create a variable, both a keyword and an identifier are bind together.

The identifiers can be altered if required, while this is not the case with keywords, which are fixed, we cannot change it according to our need. This content further elaborates the difference between a keyword and an identifier.

Keywords:

Keywords are specific reserved words in C each of which has a specific feature associated with it. Almost all of the words which help us use the functionality of the C language are included in the list of keywords. So you can imagine that the list of keywords is not going to be a small one!

There are a total of 32 keywords in C:

auto       break    case     char     const     continue

default    do       double   else     enum      extern

float      for      goto     if       int       long

register   return   short    signed   sizeof    static

struct     switch   typedef  union    unsigned  void

volatile   while

Identifiers:

Identifiers are used as the general terminology for naming of variables, functions and arrays. These are user defined names consisting of arbitrarily long sequence of letters and digits with either a letter or the underscore(_) as a first character. Identifier names must differ in spelling and case from any keywords. You cannot use keywords as identifiers; they are reserved for special use. Once declared, you can use the identifier in later program statements to refer to the associated value. A special kind of identifier, called a statement label, can be used in goto statements.

Key Differences Between Keyword and Identifier

Keywords are used to recognize the type/kind of entity while an identifier is used to name that entity uniquely. For example, if we write ‘int number’, where ‘int’ is a keyword, and ‘number’ is an identifier, i.e., this statement clearly defines that we define an entity ‘number’ which is of type int(integer).

Keywords are distinct; they are not further classified. On the contrary, if identifiers are involved in an external link process, i.e. if it include function names and global variable that are shared between files, then it is called ‘external names’, while they are not used in external link process and include the name of local variable, then it is called ‘internal names’.

The identifier can never be same as keywords, and the name of functions that are in C++ library.

Keywords defined in C++ library does not contain any symbol. Conversely, when you declare any identifier you can only use underscore but not any other symbol.

A keyword always starts with a lower case. As against, an identifier can either start with an upper case or a lower case

Conclusion

Keywords and identifiers are the building blocks of the program. They are specifically used by a compiler to uniquely define the type/kind and a name of a particular variable or a function of a class. That was all from thw segment difference between keyword and identifier.

Leave a Reply

Your email address will not be published. Required fields are marked *