We use cookies to give you the best experience possible. By continuing we’ll assume you’re on board with our cookie policy

Check Writers' Offers

What's Your Topic?

Hire a Professional Writer Now

The input space is limited by 250 symbols

What's Your Deadline?

Choose 3 Hours or More.
Back
2/4 steps

How Many Pages?

Back
3/4 steps

Sign Up and Get Writers' Offers

"You must agree to out terms of services and privacy policy"
Back
Get Offer

Variables in Computer Memory

Paper type: Essay
Pages: 3 (722 words)
Downloads: 26
Views: 3

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

  1. Variables may include Alphabets, Numbers & underscore(_) only.

  2. 1st character of a variable must be Alphabet or underscore(_).
  3. Blank spaces are not allowed in a variable name.
  4. Both upper and lower alphabets are allowed.
  5. Special characters except underscore(_) are not allowed.
  6. We cannot use Keywords as variables.
  7. A variable name must be less than or equal to 31 characters.
  8. 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:

  • int x = 10;
  • int a = -78;

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

Cite this page

Variables in Computer Memory. (2019, Dec 09). Retrieved from https://studymoose.com/variables-in-computer-memory-essay

How to Avoid Plagiarism
  • Use multiple resourses when assembling your essay
  • Use Plagiarism Checker to double check your essay
  • Get help from professional writers when not sure you can do it yourself
  • Do not copy and paste free to download essays
Get plagiarism free essay

Not Finding What You Need?

Search for essay samples now

image

Your Answer is very helpful for Us
Thank you a lot!