Unformatted text preview: ’s memory.
A variable refers to a named memory location Value of a variable The information that is stored in that location is called the value of the variable. The most common way that a variable obtains a value is by means of an assignment.
e.g. pay=4000; 33 33 Rules for Declaring Variables First character of a variable must be an alphabet or underscore. A variable begins with a letter or underscore () and may consist of letters or digits. The underscore may be used to improve the readability of the variable name.
No Special character (like # ^* etc) are allowed in a variable name except underscore.
There is no restriction on the length of a variable name. However , only the first 31 characters of variable are significant.
Both upper and lowercase letters are allowed in naming variables. An uppercase letter is considered different from a lowercase letter
Duplicate file names not allowed
Blank spaces are not allowed in a variable name
Key words/reserved words cannot be used as a variable name 34 34 Variable deceleration
In C++, the variable must be declared first and it can be used then. variables are declared with the following format: datatype var1, var2,…; d a ta ty p e s in C ++ a re int, flo a t, c h a r e tc . int fo r inte g e r typ e va ria b le , flo a t fo r flo a ting p o int va ria b le a nd c h a r fo r c h a ra c te r typ e va ria b le 35 35 Memory location When a variable is used in a computer program, the computer
associates it with a particular memory location. In other words, a variable is a space in the computer’s memory
set aside for a certain kind of data and gives a name of reference
set Void main()
View Full Document
This document was uploaded on 03/16/2014.
- Spring '14
- Computer Science