What is the difference between "keyword" and "reserved word"?
Solution 1:
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
Solution 2:
Just to show that the distinction is very meaningful:
Not in all languages are all keywords reserved words. In Fortran it is possible to do this:
if if then then else else
In this case, the keywords are not reserved, but depending on context can be interpreted by the compiler as variables.