×
☰ Menu

Variables in C

A Variable is a data name that may be used to store a data value. A variable may take different values at a different time during execution.

Variable names are names given to locations in memory. These locations can contain integer, real or character constants. In any language, the types of variables that it can support depend on the types of constants that it can handle.

Variable names consist of letters, digits, and the underscore character.

Rules for Constructing Variable Names

  • A variable name is any combination of 1 to 31 alphabets, digits or underscores. Some compilers allow variable names whose length could be up to 247 characters. Still, it would be safer to stick to the rule of 31 characters. Do not create unnecessarily long variable names as it adds to your typing effort.
  • Uppercase and lowercase are significant. That is the variable Name is not same as name of NAME.
  • The first character in the variable name must be an alphabet or underscore.
  • No commas or white space are allowed within a variable name.
  • No special symbol other than an underscore

 

Example of the valid variable name:

    • Name
    • john
    • Delhi
    • Sum_1
    • _dis1

Example of the invalid variable name:

    • 123
    • int
    • (abc)