C语言的结构体

#include <stdio.h>

int main()
{

    /*定义一个结构体*/
    struct Student{
        int age;
        short name;
    };

    /*使用这个结构体定义一个新的变量*/
    struct  Student chengqiang;



    /* typedef:给数据类型起一个别名*/
    typedef int new_int;
    int one;
    new_int  one1;
    /*此时的  new_int = int  */


    /*给结构体使用 typedef  :非成员变量里面有递归:可以省略struct后面的Student1*/
    typedef struct  Student1{
        int age;
        short name;
    } Student1;
    /*使用这个结构体定义一个新的变量*/
    Student1 chengqiang1;


    /*定义给一个结构体链表*/
    typedef struct LNode{
        /*数据*/
        int data;
        /*下一个数据的指针地址*/
        struct  LNode *next;

    } LNode;
    LNode  head;
    LNode  *p;
    /*取 head的变量的指针给p   */
    p=&head;

    //操作变量中的值
    head.data=5;
    printf("1当前head中的data为:%d \n",head.data);
    /*操作指针指向地址上的值*/
    p->data=4;
    printf("2当前head中的data为:%d \n",head.data);

    return 0;
}

输出结果为:

1当前head中的data为:5 
2当前head中的data为:4 

进程已结束,退出代码为 0

posted @ 2024-06-28 21:41  成强  阅读(5)  评论(0编辑  收藏  举报