栈的生成方向以及内存存储方式
生长方向
栈底 — 高地址
栈顶 — 低地址
内存存储方式
高位字节数据 — 高地址
低位字节数据 — 低地址
小端对齐
代码示例:
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
//1、栈的生长方向
void test01()
{
int a = 10; //栈底 --高地址
int b = 20;
int c = 30;
int d = 40;//栈顶 ---低地址
printf("%d\n",&a);
printf("%d\n", &b);
printf("%d\n", &c);
printf("%d\n", &d);
}
//2、内存储存方式
void test02()
{
int a = 0xaabbccdd;
unsigned char* p = &a;
printf("%x\n",*p);//低位字节数据 -- 低地址
printf("%x\n", *(p+1));//高位字节数据---高地址
printf("%x\n", *(p + 2));
printf("%x\n", *(p + 3));
}
int main()
{
//test01();
test02();
return EXIT_SUCCESS;
}