What is the difference between "keyword" and "reserved word"?

Piotr Dobrogost picture Piotr Dobrogost · Jul 3, 2009 · Viewed 55.2k times · Source

What's the difference between a keyword and a reserved word?

For example, in the proposal for concepts in C++ one can read the following statement:

This proposal introduces five new keywords: concept, concept map, where, axiom, and late check. All of these keywords will also be reserved words.

Answer

molf picture molf · Jul 3, 2009

Keywords have a special meaning in a language, and are part of the syntax.

Reserved words are words that cannot be used as identifiers (variables, functions, etc.), because they are reserved by the language.

In practice most keywords are reserved words and vice versa. But because they're two different things it may happen that a keyword is not a reserved word (e.g. a keyword only has meaning in a special context, and can therefore be used as an identifier), or a reserved word is not a keyword (e.g. because it is reserved for future use).

Update: Some examples as given by others that illustrate the distinction:

  • In Java, goto is a reserved word but not a keyword (as a consequence, you cannot use it at all)
  • Fortran has no reserved words, all keywords (if, then, etc.) can be used as identifiers