C程序以查找堆栈的增长方向
堆栈是一种存储元素的数据结构。堆栈上有两个操作。推送,将新元素添加到堆栈中。从堆栈中删除元素的pop。
堆栈可以根据使用它的程序的性质向上和向下增长。该程序在程序中查找堆栈增长的方向。
算法
Step 1: Create a local variable in the main function. Step 2: Create a function that with a local variable. Step 3: Call the function from the main function. And then compare the local variables of in both these functions. Step 4: Compare the address of local variables in main and the function. Step 5: If address variable in main is more than local variable of the function, then stack grows upward otherwise it grows downward.
示例
#include<stdio.h>
void fun(int *main_local_addr){
int fun_local;
if (main_local_addr < &fun_local)
printf("Stack grows upward\n");
else
printf("Stack grows downward\n");
}
int main(){
int main_local;
fun(&main_local);
return 0;
}输出结果
Stack grows downward
热门推荐
1 训练狗狗基础
2 怎么训练狗狗笑
3 怎么训练狗狗卧下
4 上海狗狗训练基地
5 训练狗狗排便
6 狗狗基础训练
8 如何训练狗狗装死
9 狗狗站姿训练
10 狗狗训练用品
11 训练狗狗吧
12 狗狗要怎么训练
13 怎么训练狗狗玩球
14 训练狗狗唤回
15 狗狗训练躺下
16 狗狗训练指令
17 狗狗的训练技巧
18 狗狗不好训练