#include <stdio.h>
#include <mm_malloc.h>
struct ListNode {
int val;
struct ListNode *next;
};
struct ListNode* init(struct ListNode* L){//tt1
/*我的实验结果告诉我:
参数里面的L容器(tt1处)有了一个全新的位置,比如0x7ffee9ec28f8,而传入
之前,L在main 里面(tt2处)的位置是: 0x7ffee9ec2928
content 倒是和main 里面,声明L时候的 content 8 一样,所以tt3 输出8
唯一不同的,就是address , tt4 就是 0x7ffee9ec28f8
所以我们 洞见 一个 事实: call by value:
tt1 的新L 把 main 里面的tt2 的L 的内容给拿了过来;
所以或许有这么一个事实: ptrX = ptrY 的时候,ptrX 就是把prtY指向地址的
内容给拿了过来。 一如 tt2 拿了 tt1 的content 8; 实际上,我还是没理解 tt5,请回答,相关: 指向指针的指针
*/
printf("content of node in init(bef), is: %d\n", L);//tt3 : 8
printf("address of node in init(bef), is: %p\n", &L);//tt4
L = (struct ListNode*) malloc (sizeof(struct ListNode*));
printf("content of node in init(aft), is: %d\n", L);//guess not 8?enen
printf("address of node in init(aft), is: %p\n", &L);//这里和tt4 的位置一样,为啥?malloc 没有分配新的空间?tt5
printf("above should be different from in main one\n");
L->val = 9;
L->next = NULL;
return L;
}
struct ListNode* fuc(struct ListNode* head)
{
printf("address of node in fuc, is: %p\n", &head);//
printf("val of node in fuc, is: %d\n", head->val);//9
return NULL;
}
int main()
{
struct ListNode* L = {8};//tt2
printf("content of node in main(bef), is: %d\n", L);
printf("address of node in main, is: %p\n", &L);//0x7ffee516c928
L = init(L);
fuc(L);
}

result:

[todo0211]c语言指针,结构体的疑问的更多相关文章

  1. C语言语法笔记 – 高级用法 指针数组 指针的指针 二维数组指针 结构体指针 链表 | IT宅.com

    原文:C语言语法笔记 – 高级用法 指针数组 指针的指针 二维数组指针 结构体指针 链表 | IT宅.com C语言语法笔记 – 高级用法 指针数组 指针的指针 二维数组指针 结构体指针 链表 | I ...

  2. 将c语言的结构体定义变成对应的golang语言的结构体定义,并将golang语言结构体变量的指针传递给c语言,cast C struct to Go struct

    https://groups.google.com/forum/#!topic/golang-nuts/JkvR4dQy9t4 https://golang.org/misc/cgo/gmp/gmp. ...

  3. go语言初始化结构体指针

    go语言初始化结构体指针 head:=&ListNode{} 或者 head:=new(ListNode)

  4. C语言中结构体赋值问题的讨论

    今天帮师姐调一个程序的BUG,师姐的程序中有个结构体直接赋值的语句,在我印象中结构体好像是不能直接赋值的,正如数组不能直接赋值那样,我怀疑这个地方有问题,但最后证明并不是这个问题.那么就总结一下C语言 ...

  5. 【AT91SAM3S】SAM3S-EK Demo工程中,LCD驱动程序的加载(函数指针结构体)

    为了调试LCD,在英倍特的板子上烧Atmel的sam3s-ek_demo_1.4_source示例代码.LCD显示正常了,却找不到LCD的驱动究竟在哪. 花了好久,追踪到了这个执行过程. 进入main ...

  6. 01.C语言关于结构体的学习笔记

    我对于学习的C语言的结构体做一个小的学习总结,总结如下: 结构体:structure 结构体是一种用户自己建立的数据类型,由不同类型数据组成的组合型的数据结构.在其他高级语言中称为记录(record) ...

  7. C语言中结构体对齐问题

    C语言中结构体对齐问题 收藏 关于C语言中的结构体对齐问题 1,比如: struct{short a1;short a2;short a3;}A;struct{long a1;short a2;}B; ...

  8. 逆向知识第十四讲,(C语言完结)结构体在汇编中的表现形式

    逆向知识第十四讲,(C语言完结)结构体在汇编中的表现形式 一丶了解什么是结构体,以及计算结构体成员的对其值以及总大小(类也是这样算) 结构体的特性 1.结构体(struct)是由一系列具有相同类型或不 ...

  9. C语言中结构体赋值问题的讨论(转载)

    今天帮师姐调一个程序的BUG,师姐的程序中有个结构体直接赋值的语句,在我印象中结构体好像是不能直接赋值的,正如数组不能直接赋值那样,我怀疑这个地方有问题,但最后证明并不是这个问题.那么就总结一下C语言 ...

  10. go语言学习-结构体

    结构体 go语言中的结构体,是一种复合类型,有一组属性构成,这些属性被称为字段.结构体也是值类型,可以使用new来创建. 定义: type name struct { field1 type1 fie ...

随机推荐

  1. AC3 Rematrix

    当L R channel highly correlated时,AC3 encoder 使用rematrix技术压缩L/R的和和差. 原始信号为left,right,使用rematrix压缩信号为le ...

  2. 【C语言】定义一个函数,求长方体的体积

    #include<stdio.h> int volume(int a, int b,int c)/*定义函数*/ { int p; p = a * b * c; return p; } i ...

  3. ASCII编码,将英文存储到计算机

    前面我们已经讲到,计算机是以二进制的形式来存储数据的,它只认识 0 和 1 两个数字,我们在屏幕上看到的文字,在存储之前都被转换成了二进制(0和1序列),在显示时也要根据二进制找到对应的字符. 可想而 ...

  4. 使用datatable动态添加的顺序与存储的顺序不一致

    原因是datatable在展示数据的时候帮助我们排序了 将其禁止排序即可:"ordering":false

  5. 搭建Hexo一键生成,同步部署

    全网最全小白搭建Hexo+Gitee/Coding/Github 全网最全小白搭建Hexo+Gitee/Coding/Github 本站内容已全部转移到https://www.myyuns.ltd,具 ...

  6. 闲来无事.gif

  7. Bugku-CTF分析篇-日志审计(请从流量当中分析出flag)

    日志审计 请从流量当中分析出flag

  8. string常用成员函数

    string常用成员函数 std::string::clear Clear string Erases the contents of the string, which becomes an emp ...

  9. 吴裕雄 python 机器学习——数据预处理标准化StandardScaler模型

    from sklearn.preprocessing import StandardScaler #数据预处理标准化StandardScaler模型 def test_StandardScaler() ...

  10. java读/写文件

    读取文件参考:https://blog.csdn.net/weixin_42129373/article/details/82154471 写入文件参考:https://blog.csdn.net/B ...