Variables and constants

  • Variable: -

An entity that may vary during program execution is called variable. Variable names are names given to memory location.
In any programs we do a lots of calculations. Using variables we can store, retrieve and manipulate data values.
Syntax: -
type var-name;
Where type is the the type of variable being declared;var-name is the variable name.
For example: -
char name;
int x;
float marks;
It is mandatory to declare the type of the variable.
Rules for constructing variables: -
  • No commas or blanks are allowed within a variable name.
  • No special symbol other than an underscore (such as in simp_inrst) can be used in a variable name.
Some of useful tips while declaring variables: -
  • The variable names should be as short as possible. This makes it easier to remember variable names.
  • It is advisable to declare meaningful variable-names. For example, if we want to maintain student database we can use variable names like name, roll_no, marks instead of using datatypes.
  • Constant
A constant is an entity that doesn’t change.
Enhanced by Zemanta
Previous
Next Post »