从程序堆栈c ++打印位置

时间:2016-07-09 15:01:07

标签: c++ printing stack

写一个函数

void printFromStack (int locations) {

//  code here

}

打印程序堆栈的最顶层位置。尝试使用以下主要代码 程序:

int main() {

int i=1;
int j=2;

char chars[] = {'a', 'b', 'c', 'd'};

printFromStack(10);

return 0;
}

上述程序应打印最顶层10个位置的内容 程序堆栈。

这是我遇到的问题,而且遇到了麻烦。

1 个答案:

答案 0 :(得分:0)

听起来像家庭作业

void printFromStack (int locations) {

int here;
for( int i = 0; i< locations; i++ ) {
    printf( "%x\n", (&here)[i] );
}

}

你的老师可能会解释一些硬件堆栈的成长和一些下降。 因此,您需要更改机器的索引。