Pages

Sunday, July 31, 2016

Rules for defining Variable Name in C language

In C language any user defined name is called identifier. This name may be variable name, function name, goto label name, any other data type name like structure, union, enum names or typedef name.

We need to follow following rules while declaring variables (identifiers) in C program.

Rule 1:  Name of identifier includes alphabets, digit and underscore.

Example of Valid variable name: india, add12, total_of_number etc.

Example of Invalid variable name: show*marks, factorial#, avg value etc.

Rule 2: First character of any identifier must be either alphabets or underscore.

Valid name:  _total, _3, a_,   etc.

Invalid name: 3_, 10_function, 12345 etc.

Rule 3: Name of identifier cannot be any keyword of c program.

Invalid name: int, float, char, if, else, for, switch, etc

Rule 4: Name of identifier is case sensitive i.e. num and Num are two different variables.

Rule 5: Only first 31 characters are significant of   identifier name.

Example:

abcdefghijklmnopqrstuvwxyz123456aaa, 

abcdefghijklmnopqrstuvwxyz123456bbb, 

abcdefghijklmnopqrstuvwxyz123456cad

All three identifier name are same because only first 31 characters has meaning. Rest has not any importance.

Rule 6: Must not contain white space.

Valid name: MyMarks

Invalid name: My Marks

* * * * *

<Back to Home>

No comments:

Post a Comment