Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 465
Piotr Dobrogost Avatar asked Jul 03 '09 11:07

Piotr Dobrogost


People also ask

Are keywords and reserved words same in Java?

Keywords are predefined which have a unique meaning and functionality in Java programming language. These keywords are also known as reserved keywords which mean they cannot be used as a variable name, class, method or any other identifier.

What is a reserved word examples?

Often found in programming languages and macros, reserved words are terms or phrases appropriated for special use that may not be utilized in the creation of variable names. For example, "print" is a reserved word because it is a function in many languages to show text on the screen.

What are keywords or reserved words in programming?

Keywords are predefined, reserved words used in programming that have special meanings to the compiler. Keywords are part of the syntax and they cannot be used as an identifier. For example: int money; Here, int is a keyword that indicates money is a variable of type int (integer).

What do you mean by reserved word?

a word in a programming language or computer system that has a fixed meaning and therefore cannot be redefined by a programmer.


1 Answers

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
like image 52
molf Avatar answered Oct 08 '22 02:10

molf