Variables & Data Types: Interactive Memory Blocks 💾

Explore how different data types are stored in computer memory.

Variables are named storage locations in computer memory that hold data values. Each variable has a specific data type that determines how much memory it occupies, what values it can store, and what operations can be performed on it. Understanding memory allocation helps programmers write efficient code and avoid common errors like buffer overflows or type mismatches. Different programming languages handle memory management differently—some allocate memory automatically while others require manual management.

Variable memory allocation visualization Hover over memory blocks to see variable declarations and data types. Memory Address 0x1000 0x1004 0x1008 0x1010 0x1018 0x1019 0x101A 0x101B int score = 95; float pi = 3.14159; string name = "Alice"; bool isActive = true; char grade = 'A'; score = 95 int (4 bytes) pi = 3.14159 float (4 bytes) name = "Alice" string (8 bytes) 'A' 'l' 'i' 'c' 'e' '\0' isActive = true bool (1 byte) grade = 'A' char (1 byte) numbers[] = {10, 20, 30, 40, 50} int array (20 bytes) 10 20 30 40 50 ptr = 0x1000 pointer (8 bytes) STACK MEMORY ↓ Growing Down main() function calculateSum() function local variables HEAP MEMORY Dynamic Allocation Object A Object B Array C Data Type Sizes: char (1 byte) bool (1 byte) int (4 bytes) float (4 bytes) string (variable)

Tip: hover or focus any highlighted area for details about memory allocation and data types.

Checkpoint Quiz: Variables & Data Types

Question 1 of 10

1. How many bytes does a typical integer variable occupy in memory?

2. Which data type is best suited for storing a single letter grade like 'A' or 'B'?

3. What is the main difference between stack and heap memory?

4. Boolean variables can store...

5. What does a pointer variable store?

6. Arrays in memory are stored...

7. Which data type would you use to store the value 3.14159?

8. String variables are essentially...

9. Memory alignment means...

10. What happens to local variables when a function ends?

Variables & Data Types Glossary