<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Aanand</title>
    <description>The latest articles on Forem by Aanand (@aanand_4d81b59bb2a50beb70).</description>
    <link>https://forem.com/aanand_4d81b59bb2a50beb70</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3538852%2F9486fe8d-b7ef-40db-8c99-7ebbaf3e6d6b.jpg</url>
      <title>Forem: Aanand</title>
      <link>https://forem.com/aanand_4d81b59bb2a50beb70</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/aanand_4d81b59bb2a50beb70"/>
    <language>en</language>
    <item>
      <title>How your compiler finds the data that is stored inside the variable (Symbol table)</title>
      <dc:creator>Aanand</dc:creator>
      <pubDate>Mon, 27 Oct 2025 05:18:59 +0000</pubDate>
      <link>https://forem.com/aanand_4d81b59bb2a50beb70/how-your-compiler-finds-the-data-that-is-stored-inside-the-variable-symbol-table-48c6</link>
      <guid>https://forem.com/aanand_4d81b59bb2a50beb70/how-your-compiler-finds-the-data-that-is-stored-inside-the-variable-symbol-table-48c6</guid>
      <description>&lt;p&gt;Have you ever typed &lt;em&gt;print(variable_name)&lt;/em&gt; and wondered how your compiler actually finds the data by using variable name? It's like magic, but there's a fascinating process working behind the scenes!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Variables are like house Addresses&lt;/strong&gt;&lt;br&gt;
Think of computer memory like a giant apartment building with millions of rooms. Each room has a number address like "Room #0x1000.&lt;/p&gt;

&lt;p&gt;when you write:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int num = 37;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here's what happens:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Find an empty room:&lt;/strong&gt; The compiler finds an available memory location (say, room #0x1000)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Move in the value:&lt;/strong&gt; The number 37 moves into this room.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Put up a name tag:&lt;/strong&gt; The variable name "num" becomes the friendly name for this address.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;The Compiler's Secret Address Book&lt;/strong&gt;&lt;br&gt;
So when your program actually runs, all those name tags disappear! how does&lt;br&gt;
&lt;em&gt;&lt;strong&gt;cout &amp;lt;&amp;lt; num&lt;/strong&gt;&lt;/em&gt; still work?&lt;br&gt;
The compiler keeps a secret address book called a symbol table:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;┌────────────┬──────────────────┐
│ Variable   │ Memory Address   │
├────────────┼──────────────────┤
│ num        │ 0x1000           │
│ age        │ 0x1004           │
│ name       │ 0x2000           │
└────────────┴──────────────────┘
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When you print a variable:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cout &amp;lt;&amp;lt; num;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;The compiler:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Looks up "num" in its address book&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Finds it lives at memory address 0x1000&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Sends instructions: "Go to address 0x1000 and print what's inside!"&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Variable names are for humans — memory addresses are for compiler!&lt;/p&gt;

</description>
      <category>c</category>
      <category>cpp</category>
      <category>programming</category>
      <category>learning</category>
    </item>
  </channel>
</rss>
