Home  >  Article  >  Backend Development  >  What does an identifier in C language consist of?

What does an identifier in C language consist of?

王林
王林Original
2020-10-23 14:31:5917938browse

C language identifiers consist of letters, numbers, and underscores, and the first character must be a letter or underscore, not a number. In identifiers, the case of letters is different. For example, BOOK and book are two different identifiers.

What does an identifier in C language consist of?

When defining variables, we use names such as a, abc, mn123. They are all given by the programmers themselves and can generally express the variables. Function, this is called an identifier.

Identifiers are names given by programmers themselves. In addition to variable names, function names, macro names, structure names, etc. will also be mentioned later. They are all identifiers.

(Recommended tutorial: C Language Tutorial)

However, the name cannot be chosen casually, and must abide by the regulations; C language stipulates that identifiers can only consist of letters (A ~Z, a~z), numbers (0~9) and underscores (_), and the first character must be a letter or underscore, not a number.

The following are legal identifiers:

a, x, x3, BOOK_1, sum5

The following are illegal identifiers:

3s cannot be used as The number starts with

s*T Illegal characters appear

*-3x It cannot start with a minus sign (-)

bowy-1 Illegal characters minus sign (-) ## appears

#You must also pay attention to the following points when using identifiers:

Although the C language does not limit the length of identifiers, it is restricted by different compilers and is also restricted by the operating system. For example, a certain compiler stipulates that the first 128 bits of an identifier are valid. When the first 128 bits of two identifiers are the same, they are considered to be the same identifier.

In identifiers, there is a difference between upper and lower case. For example, BOOK and book are two different identifiers.

Although identifiers can be defined at will by programmers, identifiers are symbols used to identify a certain quantity. Therefore, the naming should have corresponding meanings as much as possible to facilitate reading and understanding, and be "just as the name implies".

The above is the detailed content of What does an identifier in C language consist of?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn