C/C++中的参数与局部变量存储

| No Comments | No TrackBacks
store.JPG对于C/C++来说,函数的参数以及局部变量存储在堆栈中,左图展示了当一个函数被调用时其参数(parameters)以及局部变量(automatic local variables)是如何在堆栈中存储的,该数据通常被称作Activation Record。需要注意的是参数和局部变量的创建者是不同的,参数是由调用函数(caller)进行创建及初始化,局部变量则是由被调用函数(callee)创建与初始化。
下面将通过一个例子来演示参数及局部变量是如何被维护的。

void main(int argc, char** argv)
{
   int i=5;
   foo(i, &i);
}
void foo(int i, int* pi)
{
   int n = 10;
}
store2.JPG

No TrackBacks

TrackBack URL: http://lua.me/cgi-bin/mt/mt-tb.cgi/62

Leave a comment

About this Entry

This page contains a single entry by Jiang published on December 27, 2008 1:42 PM.

Taken 非常棒的动作片 was the previous entry in this blog.

PayPal account is frozen is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.