为什么我得到的地址相同的值? [英] why do i get the same value of the address?

查看:81
本文介绍了为什么我得到的地址相同的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#include<stdio.h>
#include<conio.h>

void vaibhav()
{
    int a;
    printf("%u\n",&a);
}

int main()
{
    vaibhav();
    vaibhav();
    vaibhav();
    getch();
    return 0;
} 

我每次得到变量的地址相同的值 A

这是编译器的依赖?我使用的开发C ++ IDE。

Is this compiler dependent? I am using dev c++ ide.

推荐答案

尝试从不同的堆栈深度内调用它,你会得到不同的地址:

Try to call it from within different stack depths, and you'll get different addresses:

void func_which_calls_vaibhav()
{
    vaibhav();
}

int main()
{
    vaibhav();
    func_which_calls_vaibhav();
    return 0;
}

一个局部变量的函数地址取决于在执行的时候点函数被调用堆栈(SP寄存器的值)的状态。

The address of a local variable in a function depends on the state of the stack (the value of the SP register) at the point in execution when the function is called.

在您的例子中,堆栈的状态简直是相同的每一次函数 Vaibhav的被调用。

In your example, the state of the stack is simply identical each time function vaibhav is called.

这篇关于为什么我得到的地址相同的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆