Constants and Variables

Cards (6)

  • Data values can be stored as constants or variables
  • The name of the constant or variable is linked to a memory location that stores the data value - The size of the memory location depends on the data type
  • A constant is assigned a data value at design time that can't be changed - If you attempt to change the value of a constant in a program, the interpreter or complier will return an error
  • Variables are assigned a data value that can be changed - this makes them more useful than constants
  • If you don't declare variables when the programming language requires you to , you'll receive a syntax error
  • To make code easier to follow , programmers usually follow standard naming conventions for constants and variable (e.g. 'lower case for the first letter, followed by a mixture of letters, numbers and underscores') - Variable names must not contain spaces or start with a number