码迷,mamicode.com
首页 > 其他好文 > 详细

struct函数

时间:2014-12-05 21:10:09      阅读:362      评论:0      收藏:0      [点我收藏+]

标签:style   ar   color   sp   on   bs   amp   nbsp   br   

//今天老师叫用一个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;
}

 

struct函数

标签:style   ar   color   sp   on   bs   amp   nbsp   br   

原文地址:http://www.cnblogs.com/daijiahong/p/4147332.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!