Identifiers, as the name suggests, help us to identify data and other objects in the program. Identifiers are basically the names given to program elements such as variables, arrays, and functions.
IDENTIFIERS
Identifiers,
as the name suggests, help us to identify data and other objects in the
program. Identifiers are basically the names given to program elements such as
variables, arrays, and functions. Identifiers may consist of sequence of
letters, numerals, or underscores.
Some
rules have to be followed while forming identifier names. They are as follows:
•
Identifiers cannot include any special characters or punctuation marks (like #,
$, ^, ?,., etc.) except the underscore’_’
•
There cannot be two successive underscores.
•
Keywords cannot be used as identifiers.
•
The case of alphabetic characters that form the identifier name is significant.
For example, 'FIRST' is different
from 'first' and 'First'.
•
Identifiers must begin with a letter or an underscore. However, use of
underscore as the first character must be avoided because several
compiler-defined identifiers in the standard C library have underscore as their
first char- acter. Hence, inadvertently dupli- cated names may cause definition
conflicts.
Programming Tip:
C
is a case sensitive language. If you type printf function as Printf, then an
error will be generated.
•
Identifiers can be of any reasonable length. They should not contain more than
31 characters. They can actually be longer than 31, but the compiler looks at
only the first 31 characters of the name.
Although
it is a good practice to use meaningful identifier names, it is not compulsory.
Good identifiers are descriptive but short. To cut short the identifier, you
may use abbreviations. C allows identifiers (names) to be up to 63 characters
long. If a name is longer than 63 characters, then only the first 31 characters
are used.
As
a general practice, if the identifier is a little long, then you may use an
underscore to separate the parts of the name or you may use capital letters for
each part. Examples of valid identifiers include:
roll_number, marks, name,
emp_number, basic_ pay, HRA, DA, dept code, Dept Code, RollNo, EMP NO
Examples
of invalid identifiers include:
23_student, %marks, @name,
#emp_number, basic.pay, -HRA, (DA), &dept_code, auto
Note
C is a case-sensitive
language. Therefore rno, Rno, RNo, RNO are considered as different identifiers.
Programming in C: Unit I (b): Introduction to C : Tag: : C Program - Identifiers
Programming in C
CS3251 2nd Semester CSE Dept 2021 | Regulation | 2nd Semester CSE Dept 2021 Regulation