当前位置:网站首页>栈的生长方向和内存生长方向

栈的生长方向和内存生长方向

2022-06-21 16:03:00 打酱油的;

1.栈的生长方向

栈从高至低方向生长

2.内存生长方向

小端对齐 :低字节放在低地址,高字节放在高地址(多)

大端对齐 :高字节放在低地址,低字节放在高地址(服务器)

示例代码:

//1. 栈的生长方向

void test01(){

int a = 10;

int b = 20;

int c = 30;

int d = 40;

printf("a = %d\n", &a);

printf("b = %d\n", &b);

printf("c = %d\n", &c);

printf("d = %d\n", &d);

//a的地址大于b的地址,故而生长方向向下

}

//2. 内存生长方向(小端模式)

void test02(){

//高位字节 -> 地位字节

int num = 0xaabbccdd;

unsigned char* p = #

//从首地址开始的第一个字节

printf("%x\n",*p);

printf("%x\n", *(p + 1));

printf("%x\n", *(p + 2));

printf("%x\n", *(p + 3));

}

原网站

版权声明
本文为[打酱油的;]所创,转载请带上原文链接,感谢
https://blog.csdn.net/weixin_46098612/article/details/125360640