Search⌘ K
AI Features

Where are Variables Stored?

Explore how variables are stored in memory within C# programs. Learn about memory addresses, bytes, and how declaring variables reserves memory space. This lesson helps you understand fundamental concepts of variable storage essential for effective programming.

We'll cover the following...

Introduction

A variable is a place in memory where the application can store some type of information.

You can think of memory as an "array of bytes". Each byte possesses a memory address.

Upon variable declaration, a memory location is reserved for that variable.


Example

For example, we declare an int variable which covers 4 bytes and a char variable which spans over 2 bytes of memory:

C#
using System;
namespace VariablesExampleOne
{
class Program
{
static void Main(string[] args)
{
int myInt;
char myChar;
}
}
}

You’ll learn more about variables’ types ahead.

💡Note: 1 byte = 8 bits

Cool, right? Let’s learn the variable syntax in the next lesson. ​