What is an identifier?
It is a sequence of character, which help us to identify a specific part of a program. Identifiers are names given by the programmer to program components and It is user-defined names.
name of variable
name of constant etc.,
Follow the Naming convention
It means the rules for writing identifier names. Here I have listed seven naming conventions you have to follow these rules while writing an identifier name.
- Identifiers should be meaningful. You do not write x,y,p, s like that. You should use some proper meaningful names like ‘price’, which indicates some product price, and ‘score’, which indicates some player score. Simply do not use characters for naming variables or constants or functions they are not more meaningful.
- Keywords should never be used as identifiers, like ‘continue’ it’s an invalid identifier name because ‘continue’ is a keyword. You should not use keywords as identifiers.
- The first character can be an alphabet, underscore, or dollar character. The first character should not be a number like “9thplayer”.
- After the first character, the next characters can be alphabets or underscores, or digits.
- No special characters are allowed except an underscore or dollar sign. While naming an identifier, you can use only dollar and underscore and no other special characters are allowed like you cannot use %, *, @, etc.
- More than one successive underscore or dollars should not be used like “$$balance” in the below example.
Valid identifier names:
Num , num, _flag, player9, $price, SCREEN_WIDTH, setWidth, Student etc.
Invalid identifier names:
s, p, 9thplayer, _ _flag, $$balance, etc.
I hope you guys have clearly understood what is identifiers and what are the naming conventions you have to follow while forming an identifier name.