Variables and Keywords

Rules to name a Variable

When you create a variable, you should always give a meaningful name to the variable. And follow the below rules for naming the variable:

  1. Variable name must not start with a digit.
  2. The variable name can consist of alphabets, digits, and special symbols like underscore _.
  3. Blank or spaces are not allowed in the variable name.
  4. Keywords are not allowed as a variable name.
  5. Upper and lower case names are treated as different, as C is case-sensitive, so it is suggested to keep the variable names in lower case.

Let’s see a few examples for incorrect names as per the above rules:

int 1var;    // incorrect - should not start with number
int var1;    // correct

int my$var    // incorrect - special characters not allowed
int my_var1;    // correct

int my var;    // incorrect - spaces not allowed

char else;    // can't use Keywords

int count;    // valid variable name
int Count;    // new variable
int COUNT;    // new variable

Leave a Reply

Your email address will not be published. Required fields are marked *