gpt4 book ai didi

c - 我的堆栈是向上增长而不是向下增长吗?

转载 作者:太空狗 更新时间:2023-10-29 15:03:55 25 4
gpt4 key购买 nike

<分区>

据我所知,堆栈应该向下增长。

我试着运行这段代码:

#include<stdio.h>

void func(char* a1, int a2, int a3) {

char b1[10];
int b2;
int b3;

printf("a3 address is: %p\n", &a3);
printf("a2 address is: %p\n", &a2);
printf("a1 address is: %p\n", &a1);
printf("-----------------------\n");
printf("b1 address is: %p\n", &b1);
printf("b2 address is: %p\n", &b2);
printf("b3 address is: %p\n", &b3);
}


int main() {
func("string",2,3);
return 0;
}

结果并不如我所料:

a3 address is: 0x7fff68473190
a2 address is: 0x7fff68473194
a1 address is: 0x7fff68473198
-----------------------
b1 address is: 0x7fff684731b0
b2 address is: 0x7fff684731a8
b3 address is: 0x7fff684731ac

我不希望 b1b2b3 以我声明它们的方式排序。我知道编译器可能会更改该顺序以启用优化和对齐,但为什么堆栈似乎向高地址而不是低地址增长?

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com