1. What is an identifier
Identifiers are some of the symbols and names that you customize in your program. To differentiate from keywords: the keyword is the symbol that is provided by the C language by default, and the identifier is a programmer-defined
2. The role of identifiers
1) identifiers, literally understood, are symbols used to identify something, the purpose of which is to separate it from the other.
2) In fact, the function of the identifier is similar to the human name, in order to distinguish each person, at the time of each person's birth a name
3) C language is composed of functions, a C program may have more than one function, in order to distinguish these functions, each function is given a name. The name of the function is one of the identifiers. In addition to the function, the concept of "variable" will be learned later, and the name of the variable is also the identifier
3. Naming
1> naming rules (be sure to follow)
Can only be made up of 26 letters in uppercase and lowercase, 10 Arabic numerals 0~9, underline _
Strictly case-sensitive, such as test and test are 2 different identifiers
Cannot start with a number
You cannot use a keyword as an identifier
2> naming conventions (best to follow)
Try to make a meaningful name, such as a complete English word, which can be useful if someone sees the name. If you do not understand English, you can also use pinyin, try not to be like ABCDE, SFSDFSDF and other such seemingly meaningless names
If the identifier contains more than one word, you can use the Hump logo (except for the first word, the first letter of each word is capitalized): FirstName, MyFirstName, or use the underscore _ to connect: first_name, My_first_name
1. Common identifier naming errors
Legal identifiers |
Illegal identifiers |
Comments |
FromNo12 |
From#12 |
The # symbol cannot be used in identifiers |
My_boolean |
My-boolean |
The "-" symbol cannot be used in identifiers, and the underscore "_" should be used instead |
Obj2 |
2ndObj |
Identifiers cannot start with numbers |
MyInt |
Int |
"Int" is the built-in keyword |
Jack_rose |
Jack&rose |
Symbol ' & ' cannot appear in the identifier |
Gui |
G.u.i |
The identifier must appear inside the "." Separator |
"Learning Notes", "C language" identifiers