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 3233164
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T17:14:44+00:00 2026-05-17T17:14:44+00:00

So lets say I have this code int my_static_int = 4; func(&my_static_int); I passed

  • 0

So lets say I have this code

int my_static_int = 4;
func(&my_static_int);

I passed the function a pointer to my_static_int, obviously. But what happens when the code is compiled? Avenue I’ve considered:

1) When you declare a non-pointer variable, C automatically creates its pointer and does something internally like typedefs my_static_int to be *(internal_reference)

Anyway, I hope that my question is descriptive enough

  • 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-05-17T17:14:44+00:00Added an answer on May 17, 2026 at 5:14 pm

    If you really want to know how the code looks under the covers, you have to get the compiler to generate the assembler code (gcc can do this with the -S option).

    When you truly grok C and pointers at their deepest level, you’ll realise that it’s just the address of the variable being passed in rather than the value of the variable. There’s no need for creating extra memory to hold a pointer since the pointer is moved directly from the code to the stack (the address will probably have been set either at link time or load time, not run time).

    There’s also no need for internal type creation since the compiled code already knows the type and how to manipulate it.

    Keeping in mind that this is implementation-specific, consider the following code:

    int my_static_int = 4;
    static void func (int *x) {
        *x = *x + 7;
    }
    int main (void) {
        func(&my_static_int);
        return 0;
    }
    

    which, when compiled with gcc -S to get the assembler, produces:

            .file   "qq.c"
    .globl _my_static_int
            .data
            .align 4
    _my_static_int:
            .long   4
            .text
            .def    _func;  .scl    3;      .type   32;     .endef
    _func:
            pushl   %ebp
            movl    %esp, %ebp
            movl    8(%ebp), %eax
            movl    8(%ebp), %edx
            movl    (%edx), %edx
            addl    $7, %edx
            movl    %edx, (%eax)
            popl    %ebp
            ret
            .def    ___main;        .scl    2;      .type   32;     .endef
    .globl _main
            .def    _main;  .scl    2;      .type   32;     .endef
    _main:
            pushl   %ebp
            movl    %esp, %ebp
            subl    $8, %esp
            andl    $-16, %esp
            movl    $0, %eax
            addl    $15, %eax
            addl    $15, %eax
            shrl    $4, %eax
            sall    $4, %eax
            movl    %eax, -4(%ebp)
            movl    -4(%ebp), %eax
            call    __alloca
            call    ___main
            movl    $_my_static_int, (%esp)
            call    _func
            movl    $0, %eax
            leave
            ret
    

    The important bit is these sections:

    movl    $_my_static_int, (%esp)  ; load address of variable onto stack.
    call    _func                    ; call the function.
    :
    movl    8(%ebp), %eax  ; get passed parameter (the address of the var) into eax
    movl    8(%ebp), %edx  ; and also into edx.
    movl    (%edx), %edx   ; get the value from the address (dereference).
    addl    $7, %edx       ; add 7 to it.
    movl    %edx, (%eax)   ; and put it back into the same address.
    

    Hence the address is passed, and used to get at the variable.

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

Sidebar

Related Questions

No related questions found

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.