C++: What is the difference between identifier, keyword, name and entity?
In the following, is "identifier" a name of a variable i
? Is int
a "keyword"?
int main()
{
int i;
}
I'm not being able to understand the difference between a keyword, identifier, name, entit开发者_StackOverflow中文版y.
For the variable int i
, int
is the type and i
the name. For the variable itself, i
would be the identifier; however, int
is the identifier for the type.
Types may be, but are not always, keywords. Identifiers refer to a certain object, type, etc. Names refer to an instance of an object. Entities refer to any sort of object, including basic types (int, char, etc).
i
is an identifier here. int
is a type
, actually a data type.
Identifiers:
Definition from MSDN:
An identifier is a sequence of characters used to denote one of the following:
- Object or variable name
- Class, structure, or union name
- Enumerated type name
- Member of a class, structure, union, or enumeration
- Function or class-member function
- typedef name
- Label name
- Macro name
- Macro parameter
Keywords:
C++ reserves a set of 63 words for it’s own use. These words are called keywords, and each of these keywords has a special meaning with in the C++ language.
Check out the list of keywords here.
Good Read:
What are identifiers?
What are keywords?
精彩评论