zoukankan      html  css  js  c++  java
  • [todo0211]c语言指针,结构体的疑问

    #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
    ", L);//tt3 : 8
        printf("address of node in init(bef), is: %p
    ", &L);//tt4
        L = (struct ListNode*) malloc (sizeof(struct ListNode*));
        printf("content of node in init(aft), is: %d
    ", L);//guess not 8?enen
        printf("address of node in init(aft), is: %p
    ", &L);//这里和tt4 的位置一样,为啥?malloc 没有分配新的空间?tt5
        printf("above should be different from in main one
    ");
        L->val = 9;
        L->next = NULL;
        return L;
    }
    struct ListNode* fuc(struct ListNode* head)
    {
        printf("address of node in fuc, is: %p
    ", &head);//
        printf("val of node in fuc, is: %d
    ", head->val);//9
        return NULL;
    }
    int main()
    {
        struct ListNode* L = {8};//tt2
        printf("content of node in main(bef), is: %d
    ", L);
        printf("address of node in main, is: %p
    ", &L);//0x7ffee516c928
        L = init(L);
        fuc(L);
    }
    

    result:

  • 相关阅读:
    canvas实现音乐中的歌词播放效果
    canvas调节视频颜色
    clip API实现遮罩
    总有那么几款发型 是经典不过时的
    很多人喜欢露脚踝你觉得时尚吗?
    王者荣耀花木兰攻略解析
    十位王者给出的单排心得
    IntelliJ IDEA2017 + tomcat 即改即生效 实现热部署
    IntelliJ IDEA2017 + tomcat 即改即生效 实现热部署
    jqGrid分页查询出错
  • 原文地址:https://www.cnblogs.com/paulkg12/p/12294551.html
Copyright © 2011-2022 走看看