结构体定义三种方式
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);
CGRect
CGPoint
CGSize
等