美文网首页
结构体与指针的./->

结构体与指针的./->

作者: YAOPRINCESS | 来源:发表于2020-10-21 13:39 被阅读0次

    在线编译网站

    http://www.dooccn.com/c/

    太久没写过c了,回顾一下语法

    #include <stdio.h>
    typedef struct test{
        int x;
        int y;
        struct test * pre;
        struct test * next;
    }test;
    typedef struct code{
        int x;
        int y;
        struct test* test1;
    }code;
    int main(void) { 
        test test3;
        test3.x=5;
        
        test test2;
        test2.x=3;
        test2.y=4;
        test2.next=&test3;
        
        
        code code1;
        code1.x=1;
        code1.y=2;
        code1.test1=&test2;
        
        printf("1x:%d...1y:%d...test2x:%d...test2y:%d...test3x:%d",code1.x,code1.y,code1.test1->x,code1.test1->y,code1.test1->next->x);
        return 0;
        
    }
    
    #include <stdio.h>
    typedef struct test{
        int x;
        int y;
        struct test * pre;
        struct test * next;
    }test;
    typedef struct code{
        int x;
        int y;
        struct test* test1;
    }code;
    int main(void) { 
        test test3;
        test3.x=5;
        
        test test2;
        test2.x=3;
        test2.y=4;
        test2.next=&test3;
        
        
        code code1;
        code1.x=1;
        code1.y=2;
        code1.test1=&test2;
        
        test *test4 = code1.test1;
        printf("test4:%d...\n",test4->x);
        test4=test4->next;
        printf("test4next:%d...\n",test4->x);
        
        printf("1x:%d...1y:%d...test2x:%d...test2y:%d...test3x:%d",code1.x,code1.y,code1.test1->x,code1.test1->y,code1.test1->next->x);
        return 0;
        
    }
    

    相关文章

      网友评论

          本文标题:结构体与指针的./->

          本文链接:https://www.haomeiwen.com/subject/weosmktx.html