gpt4 book ai didi

c - 为什么内存地址的&打印结束位置

转载 作者:太空宇宙 更新时间:2023-11-04 06:48:53 24 4
gpt4 key购买 nike

<分区>

据我所知,结构元素存储在连续的内存位置。为了确认这一点,我在下面编写了示例应用程序。

#include <stdio.h>

struct Employee{
char firstName;
float salary;
int id;
};


int main(){

struct Employee emp = {'K', 123456.78, 1};

printf("firstName stored at location : %lu\n", &emp.firstName);
printf("salary stored at location : %lu\n", &emp.salary);
printf("id stored at location : %lu\n", &emp.id);

return 0;
}

当我运行该应用程序时,我看到了以下类型的输出。

firstName stored at location : 140732780083504
salary stored at location : 140732780083508
id stored at location : 140732780083512

如您所见,firstName 存储在位置 140732780083504,salary 存储在位置 140732780083508,salary 不能在 140732780083505 吗?这种行为是否总是返回特定变量的结束位置。

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