(c语言版)struct指针,struct别名,struct赋初值


struc详细用法

#include
#include
int main(){
    struct F{
        char name[5];
        int age;
    }stu1={0},stu2;
    typedef struct FF{
        char name[5];
        int age;
    }stu;
    memset(&stu2,0,sizeof(stu2));
    strcpy(stu1.name,"julia");
    stu1.age=24;
    (&stu2)->age=25;
    strcpy((&stu2)->name,"Alice");
    stu mystu={0};
    stu *p=&mystu;
    strcpy(p->name,"Tom");
    p->age=26;
    printf("%s的年纪为:%d\n",stu1.name,stu1.age);
    printf("%s的年纪为:%d\n",stu2.name,stu2.age);
    printf("%s的年纪为:%d\n",p->name,p->age);
}

运行结果:
julia的年纪为:24
Alice的年纪为:25
Tom的年纪为:26

你可能感兴趣的:(c语言,c语言,开发语言)