# Import
Typedef struct students {} Stu; int main (int argc, const char * argv []) {// struct, which contains members (variables) struct teacher {char name [30]; char sex; int age; char course [30] ;}; // struct teacher Type a variable name struct teacher a = {"cuilaoshi ", 'M', 18, "language C"}; // Teacher c = {"cuilaoshi", 'M', 18, "language C"}; struct cup {float price; // price char color [30]; // color int capacity; // capacity}; // struct cup Type B variable name {20.5, "red ", 500} Initial Value struct cup B = {20.5, "red", 500}; // use typedef to redefine the type. // 1. when defining the struct, take the alias // 2. define the struct first, and then take the alias typedef struct teacher Teacher; Teacher c = {"cuilaoshi", 'M', 18, "language C "}; // The class is very similar to the struct. // The access struct member represents the struct variable. member. name strcpy (. course, "Objective-C");. sex = 'F'; // print the struct. You can print printf ("% s",. name); printf ("% c",. sex); printf ("% d",. age); printf ("% s",. course); // anonymous struct // struct value assignment // struct value can be assigned directly // There are three students, program to find the person with the highest score and the person with the least age // copy the string value assignment return 0 ;}
# Import
# Import "Student. h" # import "MyRect. h" int main (int argc, const char * argv []) {// are there three courses available? Generate, program to find the lowest score? The oldest and // the oldest? Minor # pragma mark -------------- struct array stu s [3] = {"zhangsan", {, 28 }}, {"zuoyoudong, 20 }}, {"fanghao", 24, 89, {1992,8, 8 }}; stu max = s [0]; # pragma mark ---------------- calculate the maximum and minimum values in the struct. // do not set the minimum value to 0. Otherwise, the minimum value is always 0, it can be defined as the first element s [0] stu min = s [0]; // I can start from 1 because, we have assumed that the first element s [0] is the smallest or largest, and then let it go with other elements of the array (the second and the third are ignored) for (int I = 0; I <3; I ++) {if (min. age> s [I]. age) {min. age = s [I]. age;} if (max. score
S2.score? S1: s2; // max = max. score> s3.score? Max: s3; # pragma mark ---------- memory space occupied by the struct /// allocate space sizeof // printf ("% s % lu", max. name, sizeof (stu); // minimum age person // stu min = {0}; // min = s1.age
# Import "Student. h "# pragma mark ---------- structure declaration written in. in the hfile, struct date {int year; int month; int day ;}; typedef struct date Date; typedef struct students {char name [20]; // name int age; // age float score; // score Date birthday; // birthday} stu; void bubbleSort (stu s [], int count); void printfStu (stu s [], int count );
"Student. m" void bubbleSort (stu s [], int count) {for (int I = 0; I
# Import "MyRect. h "typedef struct Lpoint {float x; float y;} Lpoint; // construct an LPointLpoint LpointMake (float x, float y); // in iOS, you will see CGPoint CGPointMake (CGFloat x, CGFloat y); // Where CGFloat comes out of typedef, typedef float CGFloat; // determine whether two vertices are the same BOOL LPointisEqual (Lpoint p1, lpoint p2); typedef struct LSize {float width; float hight;} LSize; LSize LpsizeMake (float width, float height); "MyRect. m "// construct an LPointLpoint LpointMake (float x, float y) {Lpoint p = {x, y}; return p ;} // determine whether the two points are the same BOOL LPointisEqual (Lpoint p1, Lpoint p2) {if (p1.x = p2.x & p1.y = p2.y) {return YES; // if you do not write else, it is equivalent to} else {return NO;} LSize LpsizeMake (float width, float height) {LSize siz = {width, height}; return siz ;}