标题:计算机毕业设计中认识C语言结构体
struct point1{int x;int y;};
定义结构体变量
struct point1 point;
struct{int x;int y;}point2;
struct point3{int x;int y;}point;
typedef struct point4{int x;int y;}t_point;
t_point point;
struct student{int age;char *name;};struct student ss[10];
struct student foo1 = {11, "xiaoming"};struct student foo2 = {11}
struct student foo3 = {.age = 11};
struct student foo4 = (struct student){11, "xiaoming"};struct student foo5 = (struct student){.age = 11};
struct student ss1[10] = {0};struct student ss2[10] = {{}, {}, {}};struct student ss3[10] = {[2] = {}, [3] = {}};struct student ss4[10] = {[2].age = 10, [3].name = "xiaoming"};
struct student foo = {11, "xiaoming"};int age = foo.age;char *name = foo.name;printf("age is %d, name is %s\n", age, name);foo.age = 20;foo.name = "liyong";printf("age is %d, name is %s\n", foo.age, foo.name);
当使用结构体指针的时候可以用箭头操作符”->”
struct student *pst;pst = &foo;printf("pst age is: %d and name is %s\n", (*pst).age, (*pst).name);printf("pst age is: %d and name is %s\n", pst->age, pst->name);
版权所有© 帮我毕业网 并保留所有权利