ios 结构体简述

结构体定义三种方式

第一种

struct Student1

{

    char *name;

    int age;

};

这种结构体只有结构体名字,没有变量名字

在使用的时候需要再定义一个变量如下:

struct Student1 std1 ={"123",12};

或者下面这种 都可以

struct Student1 stdu;

    stdu.name ="123";

    stdu.age =12;

还可以这样定义一个变量

typedef structStudent1 Student;

以后使用的时候直接使用  Student如下:不需要struct关键字

Student std2 = {"456",23};


还可以定义一个方法

CG_INLINE Student1

Student1Make(char *name,int age){

    Student1 std;

    std.name = name;

    std.age = age;

    return std;

}

用法

Student1 qq = Student1Make("aaa",11111);



第二种

struct  {

    char *name;

    int age;

}Student2;

这种结构体只有变量名,没有结构体名字;

使用的时候这样用:

Student2.name ="qwe";

Student2.age =22;

NSLog(@"====%s===%d",Student2.name,Student2.age);


第三种

struct Student3 {

    char *name;

    int age;

}Stydent3;

这种结构体既有结构体名字又有变量名字
1变量名字使用

Stydent3.name ="1100";

Stydent3.age =100;

NSLog(@"====%s===%d",Stydent3.name,Stydent3.age);

2结构体名字使用

struct Student3 std4 = {"www",112};

NSLog(@"====%s===%d",std4.name,std4.age);


给结构体定义一个方法

CG_INLINE Student1

Student1Make(char *name,int age){

    Student1 std;

    std.name = name;

    std.age = age;

    return std;

}

用法

Student1 qq = Student1Make("aaa",11111);




我们最常用到的结构体就是ui中的设置frame的时候,比如:

CGRect

CGPoint

CGSize




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值