Skip to main content

2.6) Defining Variables


Examples

char letter;
int x, y;
int total = 0;
float scale_factor = 1.073f;

Key Points

  • Variable definitions always start with the type of the variable
  • Variable names can be constructed from upper or lower-case letters, digits and the underscore, but cannot start with a digit; punctuation and spaces are not permitted
  • You are not required to supply an initial value for the variable; an uninitialized variable will have an unpredictable value that depends upon the existing bit pattern in the memory locations used by that variable
  • Multiple variables of a given type can be defined in a single statement (such as x and y in the examples above)
  • Variable definitions can appear anywhere within a block of code and are local in scope to that block of code