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

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

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

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

+41
language-agnostic syntax programming-languages keyword reserved-words
Jul 03 '09 at 11:17
source share
10 answers

Keywords have a special meaning in the 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 since these are two different things, it can happen that a keyword is not a reserved word (for example, a keyword makes sense only in a special context and therefore can be used as an identifier), or a reserved word is not a keyword (for example, because it is reserved for future use).

Update: some examples presented by others that illustrate the difference:

  • In Java, goto reserved word, but not a keyword (as a result, you cannot use it at all)
  • Fortran has no reserved words, all keywords (if, then, etc.) can be used as identifiers
+45
Jul 03 '09 at 11:22
source share

Just to show that the difference is very significant:

In all languages, all keywords are reserved. In Fortran, you can do this:

 if if then then else else 

In this case, the keywords are not reserved, but depending on the context, they can be interpreted by the compiler as variables.

+17
Jul 03 '09 at 11:30
source share

A good example of this difference is "goto" in Java. This is not a language keyword (that is, it is not a valid Java), but it is a reserved word.

It seems that java developers are telling us: "We will not use" goto ", nor will you."

+8
Jul 03 '09 at 11:25
source share

The wiki says this: “A keyword is a word that is special only in certain contexts, but a reserved word is a special word that cannot be used as a user-defined name.”

http://en.wikipedia.org/wiki/Reserved_word#Reserved_word_vs._keyword

+5
Jul 03 '09 at 11:20
source share

I think a keyword is a word used as a "keyword" (for example, if, for, switch, etc.), while a reserved word is something that you cannot use as a variable name, as it may become a keyword in a future version of the language.

+1
Jul 03 '09 at 11:20
source share
  • Keyword: it makes some sense, and we can use it in the program.
  • Reserved word: we cannot use in the program. They may be used in the future. Example: goto
+1
Oct 10 2018-10-10
source share

Indeed, this will be highly context sensitive. For example, the ISO C ++ standard says things like if, while, int, etc., are keywords , and don't really use the term reserved word , except once. in a footnote, where something else was probably implied :-)

The standard doe indicates reserved names — for example, all names starting with an underscore and an uppercase letter are reserved names.

0
Jul 03 '09 at 11:25
source share

Keywords: Keywords have some special functions for the compiler. Thus, keywords cannot be used as identifiers in coding. Reserved words: Reserved words are words reserved for future use. In java, const and goto are reserved words that are not currently in use and may be returned in java in the future. If we check the Java Language keywords here ( https://docs.oracle.com/javase/tutorial/java/nutsandbolts/_keywords.html ), it says that java (the latter, it seems to me) has 50 keywords, including goto and const. Thus, goto and const are keywords that are reserved.

0
Sep 24 '16 at 15:18
source share

The reserved words and keywords are basically the same, and they have predefined meanings in GW-BASIC ... they have predefined uses and cannot be used or redefined for any other purpose in Basic. Keywords cannot be used as a variable name. Some Basic keywords are ... IF , THEN , WHILE , etc.

-one
Jan 07 2018-12-12T00:
source share

keyword is a word with a special meaning in a specific context. This is a semantic definition.

a reserved word is a word that cannot be used as an identifier - such as a variable name and a function name. This is a syntax definition.

For example, in Java, all keywords are reserved words. Probably not the other way around. goto is a reserved word, but is not used and has no function.

Older languages, such as FORTRAN, had keywords, but not reserved words.

However, the keyword and the reserved word are used interchangeably.

-one
Jun 05 '17 at 18:59 on
source share



All Articles