Variables

  1. Data to be manipulated by the computer must be stored in the main memory as variables.

  2. Different data should be stored in different variables with different names.

  3. The compiler assigns a memory location or a contiguous block of memory to each variable named in the program.

  4. The amount of memory allocated depends on the type of the variable.

  5. To be sure the compiler allocates just the right amount of memory to store the data and knows how to correctly interpret the data, every variable used in the program must be declared to specify its type.

  6. The data stored in a variable is called its value.

  7. A declared variable should be given a value first before it is used to compute or generate other data.

  8. If a declared variable is used in a program before it is explicitly given a value, the result will be unpredictable since the computer will use a garbage value that is either left there by a previous program or is randomly set, and some compilers may not issue a warning or an error message.