struct函数

//今天老师叫用一个struct函数做一个函数指针循环 突然我都不知道struct函数怎么用了 害的我下去查了很多资料

第一个定义法:

int fun1(){
    struct student{
        int age;
        int nume;
    }
    struct student stu={10,20};
}

第二种定义法

int fun2(){
    struct student{
        int age;
        int nume;
    }stu={10,20};
}

第三种定义法

int fun(){
    struct {
        int age;
        int nume;
    }stu={10,20};
}

调用时候都需要printf("%d",stu.age);打印出来为10;

难点是指针调用

struct Person{
    int age;
};

void fun(){
    struct Person person = {27};
    struct Person *p;
    p=&person;
    printf("%d",person.age);
    printf("%d",(*p).age);
    printf("%d",p->age);//这三个的调用方法相同
}

int main(int argc, const char * argv[]) {
    fun();
    return 0;
}

 

posted @ 2014-12-05 19:06  代佳宏  阅读(1364)  评论(0编辑  收藏  举报