Identifiers
- Identifires are the user/programmer defined name (words).
- Identifiers refer to the following –
- Names of variables – e.g. a, b, sum, st_name, total etc.
- Name of function – e.g. fact(), lcm(), hcf(), large() etc.
- Name of arrays – e.g. int a[100]; float per[100]; here a and per is array name.
- Name of structure – e.g. struct student, here student is identifier.
- Identifiers consist of a sequence of letters and digits, with a letter as a first character.
- Both lowercase and uppercase letters are permitted.
- The underscore character is also permitted. Underscore character (_) may be allowed.
Rules for Identifiers
- First letter must be an alphabet or underscore (_).
- Must consist combination of only letters, digits or underscore.
- Uppercase and lowercase letters are significant.
- Maximum length can be 31 characters long.
- Does not contain white space.
- Should not be keywords.
Identifiers can be the name of the the following :-
(a) Variable :-
- Variable is a data name or memory reference name, which stored data value.
- Variable is a container of data values.
- A variable may take different values at different times during execution.
- The programmer can choose a variable name in a meaningful way.
Naming Rule for Variables:
- Variable name must begin with letter or underscore.
- Maximum length can be 31 characters long (in C99 63 chars long).
- Variables are case sensitive, uppercase and lowercase letters are significant (different) e.g. SUM, sum, Sum are not same there are three variables.
- Special symbols are not allowed except underscore (_).
- It should not be a keyword.
- White space is not allowed.
Examples of variable names
Valid Variable |
Invalid Variables |
_name (valid start with underscore) |
9name (invalid start with number) |
INT (Valid case sensitive) |
int (invalid due to keyword) |
Name_Per (Valid) |
Name Per ( Invalid Due White space) |
Age1 |
$Age ($ not allowed) |
A1 |
1A (first letter not allowed digit) |
xy |
x.y. (dot/period not allowed) |
Float (F is uppercase not a keyword) |
|
(b) Function (Sub-Program):
- A function is an independent block of program (code) that performs a specific task/job.
- C language allows you to define functions according to our need.
These functions are called as user-defined functions. - Function name followed by () (parenthesis) .
- When large program (regular program) break-up/de-composed into small pieces/blocks/modules
and each pieces write independently. This independent block called function and
have unique name, this name assign by the user therefore, it is identifier.
(c) Array:(Table/List/Collection of values/Set of values)
- An Array is collection of similar type of data items/values (homogeneous) store in a single variable.
- An array name followed by square bracket [ ].
- Used as contiguous memory location and fixed size storage (static memory). Array is the linear data structure.
- Array is the derived data type in C programming that is constructed from the primary/primitive data type.
- To create/declare an array we use the data type (like int/float/char etc. ).
Array Names (Identifiers) Example-
Single Dimensional
int a[100]; float list[50]; char name[25];
here a, list and name are single dimensional array names(identifiers) |
Double Dimensional
int a[100][50]; float list[50][6]; char name[50][20];
here a, list and name are double dimensional |
Three Dimensional Array
int a[10][5]]5]; float t[10][5][5];
here a and t are three dimensional array names(identifiers) |
(d) Structure and Union: (Records)
- A structure (struct) and union are group of different types of data items (or may be same)
under a single name/unit. (Pack of different-different data items). - It is user define data type (or derived data type). Created by user from existing
data type.
struct
struct student { int rl[100]; char name[25]; float per; };
Here, student is a structure name (identifier) |
union
union abc { int a; char b; float c; };
Here, abc is a union name (identifier) |
Important Questions:
1. What is variable? What are the naming rules of variable?
2. What is Identifiers?
3. What is Array? How array differ from variable?
4. Differentiate between keywords and identifiers,
5. What is C-Tokens? How many types of C-tokens.
6. What is function?
7. What is Top-down approach?
8. What is structure?
9. How many types of array.
10. How to define array name?
11. What are the differentiate between variable and constant?
12. Why identifiers used in Programming Languages?