Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9208117
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:32:50+00:00 2026-06-18T00:32:50+00:00

In C, let’s say you have a variable called variable_name . Let’s say it’s

  • 0

In C, let’s say you have a variable called variable_name. Let’s say it’s located at 0xaaaaaaaa, and at that memory address, you have the integer 123. So in other words, variable_name contains 123.

I’m looking for clarification around the phrasing “variable_name is located at 0xaaaaaaaa“. How does the compiler recognize that the string “variable_name” is associated with that particular memory address? Is the string “variable_name” stored somewhere in memory? Does the compiler just substitute variable_name for 0xaaaaaaaa whenever it sees it, and if so, wouldn’t it have to use memory in order to make that substitution?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T00:32:51+00:00Added an answer on June 18, 2026 at 12:32 am

    Variable names don’t exist anymore after the compiler runs (barring special cases like exported globals in shared libraries or debug symbols). The entire act of compilation is intended to take those symbolic names and algorithms represented by your source code and turn them into native machine instructions. So yes, if you have a global variable_name, and compiler and linker decide to put it at 0xaaaaaaaa, then wherever it is used in the code, it will just be accessed via that address.

    So to answer your literal questions:

    How does the compiler recognize that the string “variable_name” is associated with that particular memory address?

    The toolchain (compiler & linker) work together to assign a memory location for the variable. It’s the compiler’s job to keep track of all the references, and linker puts in the right addresses later.

    Is the string "variable_name" stored somewhere in memory?

    Only while the compiler is running.

    Does the compiler just substitute variable_name for 0xaaaaaaaa whenever it sees it, and if so, wouldn’t it have to use memory in order to make that substitution?

    Yes, that’s pretty much what happens, except it’s a two-stage job with the linker. And yes, it uses memory, but it’s the compiler’s memory, not anything at runtime for your program.

    An example might help you understand. Let’s try out this program:

    int x = 12;
    
    int main(void)
    {
        return x;
    }
    

    Pretty straightforward, right? OK. Let’s take this program, and compile it and look at the disassembly:

    $ cc -Wall -Werror -Wextra -O3    example.c   -o example
    $ otool -tV example
    example:
    (__TEXT,__text) section
    _main:
    0000000100000f60    pushq   %rbp
    0000000100000f61    movq    %rsp,%rbp
    0000000100000f64    movl    0x00000096(%rip),%eax
    0000000100000f6a    popq    %rbp
    0000000100000f6b    ret
    

    See that movl line? It’s grabbing the global variable (in an instruction-pointer relative way, in this case). No more mention of x.

    Now let’s make it a bit more complicated and add a local variable:

    int x = 12;
    
    int main(void)
    {  
        volatile int y = 4;
        return x + y;
    }
    

    The disassembly for this program is:

    (__TEXT,__text) section
    _main:
    0000000100000f60    pushq   %rbp
    0000000100000f61    movq    %rsp,%rbp
    0000000100000f64    movl    $0x00000004,0xfc(%rbp)
    0000000100000f6b    movl    0x0000008f(%rip),%eax
    0000000100000f71    addl    0xfc(%rbp),%eax
    0000000100000f74    popq    %rbp
    0000000100000f75    ret
    

    Now there are two movl instructions and an addl instruction. You can see that the first movl is initializing y, which it’s decided will be on the stack (base pointer – 4). Then the next movl gets the global x into a register eax, and the addl adds y to that value. But as you can see, the literal x and y strings don’t exist anymore. They were conveniences for you, the programmer, but the computer certainly doesn’t care about them at execution time.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have an abstract parent class called shape, and that there are
Let me explain best with an example. Say you have node class that can
Let's say that I have a SQLite database that I create in a separate
Let's say for a moment that I have the following module in python: class
Let's say I have some text as follows: do this, do that, then this,
Let's say you have a class library project that has any number of supplemental
Let's say I want to write a function that validates an email address with
let's say.. I have the following java bean. Case1: (Student Bean) Integer id; String
Let say I have my view that I use it as a toggle button.
Let's say, I have an application that access(read/write) the file system(files inside application), Active

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.