Variable Naming Conventions

  • Variable names must start with a letter or underscore.
  • By convention a lower case letter.
  • The use of a leading underscore is NOT recommended.
  • Then letters, numbers and the underscore _ can be used.
  • Spaces are NOT allowed.Do NOT use any of the C reserved keywords.
  • Case is significant, num is a different variable to NumOnly the first 31 characters are significant.


  • Names should be meaningful or descriptive.
    • E.g. studentAge or student_age is more meaninful than age,
  • Spaces
    • are either replaced by the underscore, e.g. account_name
    • the space removed and the second name started with an uppercase letter e.g. accountName.
  • If you are attending further education or working as part of a team, then additional naming conventions may be required.

Variable Declaration

Before you can use a variable you must declare it. Decide what type of data is going to be stored in variable. The main categories of data are:

integers e.g. 0, 1, 99, 12345
floating point numbers e.g. 12.543, 0.5, 1.00.
characters e.g. a, Z, 3, # etc. Note: Characters are stored as a number that is the ASCII code for that character.
strings Strings can't be declared as a string. They are regarded as an array of characters, and are dealt with later.

Table of Variable types.

Variable Type Keyword Range Storage in Bytes
Character char -127 to 127
Unsigned character unsigned char 0 to 255
Integer int -32,768 to 32,767
Unsigned integer unsigned int 0 to 65,535
Short integer short -32,768 to 32,767
Unsigned short integer unsigned short 0 to 65,535
Long integer long -2,147,483,648 to 2,147,483,647
Unsigned long integer unsigned long 0 to 4,294,967,295
Single precision floating point float 1.2E-38 to 3.4E38, approx. range precision = 7 digits.
Double precision floating point double 2.2E-308 to 1.8E308, approx. range precision = 19 digits.

The main variable types that you will use most are char, int, float. If you wish to use larger numbers than those allowed in int and float then refer to this table for the type you should use.

Variable Declaration Examples

Single declarations

int age;
float amountOfMoney;
char initial;

Multiple declarations

int age;
int houseNumber;
int age, houseNumber, quantity;
float distance, rateOfDiscount;
char firstInitial, secondInitial;

The reference site for this content is