Variables

We store every kind of data in variables. Variables are locations in memory for storing data. The memory is divided into blocks. It can be viewed as pigeon-holes. You can think of it as PO Boxes also. In post offices there are different boxes and each has an address. Similarly in memory, there is a numerical address for each location of memory (block). It is difficult for us to handle these numerical addresses in our programs. So we give a name to these locations. These names are variables. We call them variables because they can contain different values at different times.

The variable names in C may be started with a character or an underscore ( _ ). But avoid starting a name with underscore ( _ ). C has many libraries which contain variables and function names normally starting with underscore ( _ ). So your variable name starting with underscore ( _ ) may conflict with these variables or function names.

In a program every variable has:
  • Name
  • Type
  • Size
  • Value
The variables having a name, type and size (type and size will be discussed later) are just empty boxes. They are useless until we put some value in them. To put some value in these boxes is known as assigning values to variables. In C language, we use assignment operator for this purpose.

For previous lesson click here: Our First Program,c++ First program
For next lesson click here: Assignment Operator


the easiest way to learn programming
introduction to programming
Variables

0 comments:

Post a Comment

 

introduction to programming Copyright © 2011-2012 | Powered by Blogger