Identifiers
Identifiers are names for entities in a C program, such as variables, arrays, functions, structures, unions and labels. An identifier can be composed only of uppercase, lowercase letters, underscore and digits, but should start only with an alphabet or an underscore. If the identifier is not used in an external link process, then it is called as internal. Example: Local variable. If the identifier is used in an external link process, then it is called as external. Example: Global variable
An identifier is a string of alphanumeric characters that begins with an alphabetic character or an underscore character that are used to represent various programming elements such as variables, functions, arrays, structures, unions and so on. Actually, an identifier is a user-defined word. There are 53 characters, to represent identifiers. They are 52 alphabetic characters (i.e., both uppercase and lowercase alphabets) and the underscore character. The underscore character is considered as a letter in identifiers. The underscore character is usually used in the middle of an identifier. There are 63 alphanumeric characters, i.e., 53 alphabetic characters and 10 digits (i.e., 0-9).
Rules for constructing identifiers
1. The first character in an identifier must be an alphabet or an underscore and can be followed only by any number alphabets, or digits or underscores.
2. They must not begin with a digit.
3. Uppercase and lowercase letters are distinct. That is, identifiers are case sensitive.
4. Commas or blank spaces are not allowed within an identifier.
5. Keywords cannot be used as an identifier.
6. Identifiers should not be of length more than 31 characters.
7. Identifiers must be meaningful, short, quickly and easily typed and easily read.
Valid identifiers: total sum average _x y_ mark_1 x1
Invalid identifiers
1x - begins with a digit
char - reserved word
x+y - special character
Note: Underscore character is usually used as a link between two words in long identifiers.
kinds of identifiers
C defines two kinds of identifiers:
Internal identifier
If the identifier is used in an external link process, then it is called as external. These identifiers are also known as external names; include function names and global variable names that are shared between source files. It has at least 63 significant characters.
External identifier
If the identifier is not used in an external link process, then it is called as internal. These identifiers are also known as internal names; includes the names of local variables. It has at least 31 significant characters.
Differentiate between Keywords words and identifiers
Keyword Identifier
Predefined-word User-defined word
Must be written in lowercase only Can written in lowercase and uppercase
Has fixed meaning Must be meaningful in the program
Whose meaning has already been explained to the C compiler Whose meaning not explained to the C compiler
Combination of alphabetic characters Combination of alphanumeric characters
Used only for it intended purpose Used for required purpose
Underscore character is not considered as a letter Underscore character is considered as a letter
Questions
An identifier is a string of alphanumeric characters that begins with an alphabetic character or an underscore character that are used to represent various programming elements such as variables, functions, arrays, structures, unions and so on. Actually, an identifier is a user-defined word. There are 53 characters, to represent identifiers. They are 52 alphabetic characters (i.e., both uppercase and lowercase alphabets) and the underscore character. The underscore character is considered as a letter in identifiers. The underscore character is usually used in the middle of an identifier. There are 63 alphanumeric characters, i.e., 53 alphabetic characters and 10 digits (i.e., 0-9).
Rules for constructing identifiers
1. The first character in an identifier must be an alphabet or an underscore and can be followed only by any number alphabets, or digits or underscores.
2. They must not begin with a digit.
3. Uppercase and lowercase letters are distinct. That is, identifiers are case sensitive.
4. Commas or blank spaces are not allowed within an identifier.
5. Keywords cannot be used as an identifier.
6. Identifiers should not be of length more than 31 characters.
7. Identifiers must be meaningful, short, quickly and easily typed and easily read.
Valid identifiers: total sum average _x y_ mark_1 x1
Invalid identifiers
1x - begins with a digit
char - reserved word
x+y - special character
Note: Underscore character is usually used as a link between two words in long identifiers.
kinds of identifiers
C defines two kinds of identifiers:
- Internal
- External
Internal identifier
If the identifier is used in an external link process, then it is called as external. These identifiers are also known as external names; include function names and global variable names that are shared between source files. It has at least 63 significant characters.
External identifier
If the identifier is not used in an external link process, then it is called as internal. These identifiers are also known as internal names; includes the names of local variables. It has at least 31 significant characters.
Differentiate between Keywords words and identifiers
Keyword Identifier
Predefined-word User-defined word
Must be written in lowercase only Can written in lowercase and uppercase
Has fixed meaning Must be meaningful in the program
Whose meaning has already been explained to the C compiler Whose meaning not explained to the C compiler
Combination of alphabetic characters Combination of alphanumeric characters
Used only for it intended purpose Used for required purpose
Underscore character is not considered as a letter Underscore character is considered as a letter
Questions
- Write short notes on: Identifiers.
- What are identifiers in C? Give examples?
- Define identifier. What are the rules to be followed for identifiers?
- What are the different types of identifiers in C?
- What is an internal identifier?
- What is an external identifier?