Variables in Computer Memory Free Essay Example
Variable
A variable is a named memory location or memory cell. It is used to store program’s input data and its computational results during execution. The value of a variable may change during the execution of a program. However, the name of a variable cannot be changed.
The Variables are created in RAM. RAM is a temporary memory. That is why data stored in variables is also temporary. The data stored in a variable is automatically removed when the program is ends.
Computer Memory
- Address of a variable
- Name of a Variable Value of a variable
- Variable in memory
Name of a Variable: It is the name of memory which we reserve in RAM.
Value of a variable: It is representing which value we given to a variable.
Address of a variable: It is referring to the memory location of a variable.
Variable Declaration
The process of specifying the variable name and its type is known as variable declaration.
Syntax:
data_type variable_name;
Examples:
- int Marks;
- float _average;
- char grade;
- double mySalary;
Rules of declaration of a variable
- Variables may include Alphabets, Numbers & underscore(_) only.
- 1st character of a variable must be Alphabet or underscore(_).
- Blank spaces are not allowed in a variable name.
- Both upper and lower alphabets are allowed.
- Special characters except underscore(_) are not allowed.
- We cannot use Keywords as variables.
- A variable name must be less than or equal to 31 characters.
- A variable must be declared with one data type only.
Examples:
- int Room;
- char myName_is;
- float _Numbers;
Some examples of declare wrong variables
- int 9words;
- float No#;
- char My name is;
- int float;
Variable Initializing
The process of assigning a value of a variable at the time of its declaration is known as variable initialization.
Syntax:
data_type variable_name = value;
Examples:
- int Marks = 75;
- float _average = 89.34;
- char grade = A;
- double mySalary = 49700;
Data Type
The data type defines set of values and the set of operation on those values. The data is process according to its data type and return the output. The data and its type are define before the designing of actual program. A C++ program has many data types. Each data type require different amount of memory. C++ language provides the following data types:
Data Type Purpose
- Int To store Numeric values
- Float To store Real values
- Double To store Very large values
- Char To store Character values
Integer Data Type
Integer data type is store only numeric values with no decimal and fraction point. It includes both positive and negative values.
Examples:
Types of Integer
C++ provides these types of integer values:
- Data Type Size in Bytes Description
- int 2 Range from -32,768 to 32767
- Short 2 Range from -32,768 to 32767
- unsigned int 2 Range from 0 to 65,535
- Long 4 Range from-2,147483648 to 2,147483648
- unsigned long 4 Range from 0 to 4,294,967,295
Float Data Type
Floating data type is numeric value with decimal and fractional points. It is also known as Real data type.
Examples:
- float m = 12.93;
- float b = 89.804;
Types of Float
Data Type Size in Bytes Description
- Float 4 Range from 3.4×10-38 to 3.4×10+38
- Double 8 Range from 1.7×10-308 to 1.7×10+308
- long double 10 Range from 1.7×10-4932 to 1.7×10+4932
Escape Sequence
The backslash is used as a marker character to tell the compiler that the next character has some special meaning. What that next character means is, up to the implementation. For Example, C-style languages use n to mean newline and t to mean tab. The use of the word “escape” really means to temporarily escape out of parsing the text and into another mode where the subsequent character is treated differently.
Types of Escape Sequences:
Below is the list of some usually used escape sequences in C++;
Escape Sequences Description
- n Newline. Position the screen cursor to the beginning of the next line.
- t Horizontal tab. Move the screen cursor to the next tab stop.
- a Alert. Sound the system bell.
- Backslash. Used to print a backslash character.
- Single quote. Used to print a single quote character.
- Double quote. Used to print a double quote character.
Example:
To understand the concept of escape sequence more precisely, consider the following sample program as an example.
- using namespace std;
- int main()
- {
- cout
Top-quality papers guaranteed
100% original papers
We sell only unique pieces of writing completed according to your demands.
Confidential service
We use security encryption to keep your personal data protected.
Money-back guarantee
We can give your money back if something goes wrong with your order.
Enjoy the free features we offer to everyone
-
Title page
Get a free title page formatted according to the specifics of your particular style.
-
Custom formatting
Request us to use APA, MLA, Harvard, Chicago, or any other style for your essay.
-
Bibliography page
Don’t pay extra for a list of references that perfectly fits your academic needs.
-
24/7 support assistance
Ask us a question anytime you need to—we don’t charge extra for supporting you!
Calculate how much your essay costs
What we are popular for
- English 101
- History
- Business Studies
- Management
- Literature
- Composition
- Psychology
- Philosophy
- Marketing
- Economics