Home>Article>Backend Development> Learn about custom identifiers and rules in C language in three minutes

Learn about custom identifiers and rules in C language in three minutes

烟雨青岚
烟雨青岚 forward
2020-07-08 11:49:48 9799browse

Learn about custom identifiers and rules in C language in three minutes

#Identifiers in C language include: keywords, predefined identifiers, user identifiers

1. Keywords: Not allowed as user ID. main define scanf printf are not keywords. What confuses you is that If can be used as a user identifier. Because the first letter in If is capitalized, it is not a keyword.

2. Predefined identifiers are identifiers predefined by the system in C language, such as system class library names, system constant names, and system function names.

Predefined identifiers have the characteristics of clear meaning, such as the function "format output" (full English name plus abbreviation: printf), "format input" (full English name plus abbreviation: scanf), sin, isalnum, etc. wait.

Predefined identifiers can be used as user identifiers, but this will lose the original meaning specified by the system, and improper use will cause program errors.

3. User identifier: An identifier defined by the user according to his or her needs.

is generally used to name variables, functions, arrays, etc. If the user identifier is the same as the keyword, an error will occur during compilation; if

is the same as the predefined identifier, no error will occur during compilation, but the original meaning of the predefined identifier will be lost, or the result will be incorrect. , so predefined identifiers are generally not used as user identifiers.

There are 5 rules for custom identifiers in C language:

1. Identifiers can only be composed of letters, numbers, and underscores. Other characters are illegal. of.

2. The first character of the identifier must be a letter or an underscore. For example: char 66A is an illegal definition (because the first character is a number) char A66 is a correct identifier definition.

3. There is a difference between upper and lower case in identifiers in C language. For example: int A and int a are two different definitions. A and a are two different integer variables.

4. The maximum length of an identifier is only 8 bytes, and any extra bytes will be ignored. So for int student666 and student 999 will be considered as two same variables in C language.

5. The C language identifier definition cannot have the same name as the C language default keyword. Common keywords include: int if else switch printf define etc. For specific information, please refer to the C language technical documentation.

Thank you everyone for reading, I hope you will benefit a lot.

This article is reproduced from: https://blog.csdn.net/qq_26079093/article/details/93372724

Recommended tutorial: "C Language Tutorial"

The above is the detailed content of Learn about custom identifiers and rules in C language in three minutes. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete