Monday, 19 October 2026Mon, 19 Oct 2026 All-India deskIndia Admit cardsAdmit Results
Quizzes Am I eligible?

Variables and Data Types: Storing Values in Memory

WhatsAppX
Variables and Data Types: Storing Values in Memory, Grammar · Beginner | jijnas.com

Variables and Data Types: Storing Values in Memory

The Daily-Life Doorway: Labeled Storage Boxes

Imagine you have a row of plastic storage boxes on a shelf in your room. On the outside of each box, you stick a bright label like "Age", "Player Name", or "High Score". Inside the box labeled "High Score", you slip a piece of paper with the number 100 written on it.

When you beat your record, you do not throw away the box. You take out the paper showing 100, erase it, and put in a new paper showing 150. The box label stays the same, but the item inside changes. In computer programming, a variable is simply a labeled memory box that holds one piece of information at a time.

What Is a Variable and What Is a Data Type?

Your computer's memory is a massive grid of billions of tiny storage slots. A variable gives a human-friendly name to one of those storage slots so you can find it later. Every piece of information stored inside a variable belongs to a specific data type.

Just as you would not store soup in a cardboard box, a computer needs to know what kind of data it is holding so it knows how to handle it. The four primary data types used in almost every program are:

  • Integer: Whole numbers without decimal points, like 12, 0, or -5.
  • Floating-Point (Float): Numbers that contain decimal points, like 19.99 or 3.14.
  • String: Text characters wrapped inside quotation marks, like "Aarav" or "Hello World".
  • Boolean: A simple logical flag that can only be True or False.

Core Rules of Variables

To use variables correctly, you must follow three fundamental rules of computer memory:

  1. Assignment side: The variable name always sits on the left side of an equals sign, and the value sits on the right.
  2. Overwriting: Putting a new value into a variable erases whatever was inside that box before.
  3. Quotes dictate type: Any text inside quotation marks becomes a string, even if the characters inside look like a number.

Pseudocode Walkthrough: Storing and Updating Memory

Let us trace how a computer handles variables step by step in plain pseudocode.

// Step 1: Create a variable named score and put 10 inside it
SET score TO 10

// Step 2: Add 5 to the current value of score and store the new result back in score
SET score TO score + 5

// Step 3: Create a string variable for the player name
SET player_name TO "Aarav"

// Step 4: Create a boolean flag for the game status
SET is_game_over TO False

In Step 1, the computer reserves a memory slot, labels it score, and marks it as an integer holding 10. In Step 2, the computer reads the current value (10), adds 5 to make 15, and overwrites the old 10 with 15 inside the same box.

Comparing Data Types

Understanding how data types differ helps you choose the right container for your program's data.

Data Type Example Value What the Computer Sees Common Use Case
Integer 12 A whole number ready for math Counting items, age, player score
Float 19.99 A decimal value with fractional parts Prices, exact measurements, weight
String "12" or "Aarav" A sequence of visual text characters Usernames, email addresses, messages
Boolean True A binary 1 or 0 logical switch Checking if logged in, game over flags

Where This Breaks in Real Programs

A classic issue occurs when you mix text strings with mathematical numbers. To a human, "5" and 5 look identical. To a computer, 5 is a number that can be added, while "5" is a picture of a character.

If you try to perform math on a string, such as adding "10" + 5, the program will crash or produce unexpected results. You must convert the string into a whole number before performing arithmetic operations.

Where This Sits in a Real Career

Every software engineer, from game developers building physics engines to data analysts tracking financial markets, starts by picking the correct data type. Selecting an inefficient or incorrect data type can lead to memory leaks, slow performance, or critical calculation bugs in real-world applications.

Deeper Rules and Hidden Exceptions

As you build larger programs, variables behave in ways that can surprise you if you do not know what happens inside computer memory.

Imagine you have a piece of paper on your desk where you write down a math answer. If a friend copies that number onto their own sheet of paper, changing the number on your paper later does not automatically change what is written on your friend's paper. They are two separate sheets of paper.

In programming, calculation variables work the exact same way. Look at this pseudocode:

// Step 1: Set item_price to 100
SET item_price TO 100

// Step 2: Calculate total_cost based on item_price
SET total_cost TO item_price + 20

// Step 3: Change item_price to 50
SET item_price TO 50

A common myth is that changing item_price to 50 in Step 3 will automatically update total_cost to 70. It does not. When Step 2 runs, the computer calculates 100 + 20 and puts 120 inside the total_cost box. Step 3 changes item_price, but total_cost stays at 120 unless you run the calculation step again.

Another surprise involves floating-point numbers. Imagine trying to divide a single apple equally among three friends. Each person gets roughly 0.3333 apples, but no matter how many decimals you write down, you can never write the exact fractional amount using simple decimal numbers. Computers face the same problem when converting decimal math into binary chips. Calculating 0.1 + 0.2 in a program often produces 0.30000000000000004 instead of exact 0.3. When writing software for banks, programmers avoid simple floating-point numbers to prevent losing fractions of a cent.

Mistakes That Cost Marks

When writing code in exams or practical tests, small structural mistakes can stop a program from running completely. Here are four common mistakes and how to fix them:

Mistake 1: Flipping the Assignment Operator

Wrong:

100 TO score

Right:

SET score TO 100

Why: The computer always expects the variable name on the left side of the assignment sign, receiving a value from the right side.

Mistake 2: Adding Spaces inside Variable Names

Wrong:

SET user age TO 15

Right:

SET user_age TO 15

Why: A computer reads a space as a separator between two different commands. Use an underscore (_) to connect words in a single variable name.

Mistake 3: Mixing String Characters with Math Numbers

Wrong:

SET final_score TO "10" + 5

Right:

SET final_score TO 10 + 5

Why: "10" is stored as text characters, while 5 is a mathematical integer. You must use whole numbers without quotation marks to perform math operations.

Mistake 4: Lowercase Boolean Keywords

Wrong:

SET is_passed TO true

Right:

SET is_passed TO True

Why: Most strictly structured systems require boolean flags like True and False to start with a capital letter.

How You Are Tested in Exams and Practical Work

School exams test your ability to trace code step by step without running it on a computer. You will often be given a block of pseudocode with multiple reassignments and asked to write down the final value stored inside each memory box at the end.

In technical interviews and professional projects, companies test your judgment in choosing the right data type for efficiency. Storing an age as a string wastes unnecessary memory space, while using an integer for a phone number removes leading zeros like 01234, breaking the contact data.

Ready to Put Your Memory Boxes to the Test?

You now understand how computer memory reserves named slots, how values overwrite each other, and how data types govern what operations you can perform. Move on to the practice questions to test your skill in identifying data types and tracing variable values!

Discussion

0 be kind · most people here are students
No comments yet, be the first voice here. 🌱

💬 Understanding How Memory Boxes Work

You

What actually happens inside the computer when I write a line of code like score = 10?

Guru

Imagine placing a toy inside a labeled box on your closet shelf. The computer reserves a box in memory, labels it score, and places the integer 10 inside it.

You

What happens if I write score = score + 5 on the very next line? Does it create a second box?

Guru

No, a memory box can only hold one value at a time. The computer takes 10 out, adds 5 to get 15, and puts 15 back into score, completely overwriting 10.

You

What if I put quotes around the number, like item_count = "5"?

Guru

Quotation marks change everything. The computer now sees text characters instead of a number, making it a string data type that cannot do math.

You

So code variables are not like algebra equations where x always equals y plus 2?

Guru

Exactly. Algebra describes permanent equality. Code is a sequential list of memory storage commands that run step by step from top to bottom.

🧭 Which Data Type Should You Use?

Answer each question, get to the fix. Take the same path you would at the bench.

See the whole map at once
  1. Is your piece of information wrapped in quotation marks or made of text characters?Yes, it is textNo, it is not text
  2. Store it as a String. Examples include player_name = "Aarav" or digit strings like item_count = "5". → String (Text)
  3. Is the piece of data a simple yes/no flag set to True or False?Yes, True/FalseNo, it is a number
  4. Store it as a Boolean flag. Examples include is_game_over = False or is_passed = True. → Boolean (Logical Flag)
  5. Does the number contain a decimal point or a fractional part?Yes, has decimalsNo, whole number
  6. Store it as a Floating-Point number. Example: price = 19.99. → Float (Decimal Number)
  7. Store it as an Integer. Examples include age = 12 or score = 10. → Integer (Whole Number)

🕐 Tracing Memory Changes Line by Line

  1. Line 1: age = 12Step 1

    The computer creates a memory box named age and stores the whole number 12 as an integer.

  2. Line 2: score = 10Step 2

    A separate memory box named score is created, holding the integer value 10.

  3. Line 3: score = score + 5Step 3

    The computer evaluates the right side (10 + 5 = 15) and overwrites the score box with 15.

  4. Line 4: player_name = "Aarav"Step 4

    A new memory box named player_name is assigned the string sequence "Aarav".

  5. Line 5: is_game_over = FalseStep 5

    A boolean decision flag holding False is created in memory under the name is_game_over.

🔍 Variable Myths vs Programming Reality

MythVariables permanently hold values like a mathematical algebra equation.

RealityA variable is a temporary storage box. Changing a variable on one line overwrites its memory box and does not update other variables set earlier in the program.

MythThe text string "100" and the integer number 100 are identical to the computer.

RealityThe integer 100 is stored as a binary quantity for math calculations. The string "100" is stored as three text characters and causes errors if added to a number.

MythYou can format variable names with spaces, like user name = "Priya".

RealityVariable names cannot contain spaces or sit on the right side of the assignment operator. You must use underscores like user_name = "Priya" and keep the variable name on the left.

MythComputers calculate floating-point decimal numbers with perfect accuracy.

RealityBinary memory cannot represent every decimal fraction exactly. Operations like 0.1 plus 0.2 can result in floating-point artifacts like 0.30000000000000004.

🧺 Sort these values into their true types

Drag each value into the bucket it belongs to. On a phone, tap the card, then tap its bucket.

Sort every card into its bucket · 0 / 10 sorted
String
Integer
Float
Boolean
See the sorted answer key
  • String: "Aarav", "2026", "True"
  • Integer: -7, 42, 0
  • Float: 3.14, 19.99
  • Boolean: True, False

Right vs Wrong: spot the trap

✗ The trap

total = "10" + 5

✗ The trap

5 = score

✗ The trap

user name = "Priya"

✗ The trap

is_passed = true

Try It Yourself

0 solved
1
Which data type should you choose to store a product price like 24.99?
2
What is the final value stored inside the variable 'count' after running these lines? SET count TO 5 SET count TO count + 3 SET count TO 2
3
What is the data type of the value stored in item_code = "450"?
4
Identify the syntax error in this statement: SET player score TO 100
5
What happens if a program attempts to evaluate the expression "20" + 10 without type conversion?
6
Which data type can store only two possible values: True or False?