Saturday, 5 October 2013

C Identifiers - Rules and Conventions

C Identifiers


The programmer uses his own words for preparing a program. These words are used to store final or intermediate results. These words are called identifiers. The programmer has to define the type of identifier he is using. For example – a, b, sum, etc.

There are two categories of identifiers:

Category- I          (i) Variable          (ii) Constant      

Category - II       (i) Numeric         (ii) String

So there can be four types as illustrated in below table:

Type
Example
Numeric variable
int a;
Numeric constant
#define  PI   3.14
String variable
char * str;
String constant
const char * name=”RGPV”;

 

Rules and Conventions of making identifiers: – 

Rules:  

·         The first character must be an alphabet. Remaining characters may be alpha numerals.    

·         Space is not permitted.

·         No special character other than underscore ‘_’ is permitted.      

·         The maximum length is compiler identifier.

Conventions:    

·         The identifier name should be such that it should reflect its purpose.

·         The identifier should not be too large.  

·         The variable identifier is taken in small case. For ex.  int   a, b, sum;

·         Constant identifier is taken in capital case. For ex.   #define  PI  3.14.       

·         Confusing names should be avoided.

 

Some examples of c identifiers:

Name
Remark
_A9
Valid
Temp.var
Invalid as it contains special character other than the underscore
void
Invalid as it is a keyword

 

No comments:

Post a Comment