Jan 5, 2015

Keywords and Reserved Words


                           Keywords are predefined identifiers, that are used in the syntax and can be used as identifiers again.

                 Reserved words are the words in a programming language which has a fixed meaning and cannot be redefined by the programmer. They cannot be used as identifiers (variables, functions etc).
  • All reserved words and keywords are in lowercase letters.

  • But be aware that this terminology is not standard. For example, In some books it was mentioned that Reserved words are also called as Reserved Keywords and some authors will use keyword in the same sense that we have used Reserved word.
  • In fact all keywords are subset of Reserve words.
  • Keywords can be redefined while Reserved words cannot be redefined and used.

    For example : 
 
              Here main is the keyword. So it can be redefined and used as an identifier.
Output :
            1

Example :
                Here auto is an Reserved word. It cannot be redefined. So it gives an error.
               In general reserved words and keywords need not coincide, but in most modern programming languages, keywords are a subset of reserved words, as this makes parsing easier, since keywords cannot be confused with identifiers. In some languages, like C or Python, reserved words and keywords coincide, while in other languages, like Java, all keywords are reserved words, but some reserved words are not keywords – these are "reserved for future use".


Here is a list of Reserved words and keywords.

C++ Reserved words :

                     The reserved words of C++ may be conveniently placed into 3 groups. In the first group we put those that were also present in the C programming language and have been carried over into C++. There are 32 of these, and here they are:


                There are another 30 reserved words that were not in C, are therefore new to C++, and here they are:



                   The following 11 C++ reserved words have been added to provide more readable alternatives for some of the C++ operators, but they are not essential when the standard ASCII character set is being used.
 


Predefined Identifiers :

                      Here is a very short list of some of the predefined identifiers :


Filed under  |