-
Notifications
You must be signed in to change notification settings - Fork 0
/
01struct.c
63 lines (50 loc) · 1.22 KB
/
01struct.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <stdio.h>
#include <io_utils.h>
int main() {
/*
* struct <结构体名> {
* <成员类型> <成员名>;
* ...
* } <结构体变量>;
*/
typedef struct Company {
char *name;
char *id;
char *location;
} Company;
typedef struct Person {
char *name;
int age;
char *id;
Company *company;
Company company2;
struct {
int extra;
char *extra_str;
} extra_value;
struct Person *partner;
} Person;
Company company = {.name="aaa", .id="1212121"};
struct Person person = {.name="bbbb", .id="12113322222", .company=&company,
.company2={.name="cccc", .id="32323232"}, .extra_value={.extra=6}
};
printf("it is %d, %d\n", sizeof(char *), sizeof(struct Company));
PRINT_INT(person.age);
person.age = 30;
// person.company2.name
// person.company->name
//person.extra_value.extra
PRINT_HEX(&person);
Person *person_ptr = &person;
puts(person_ptr->name);
PRINT_INT(sizeof(Person));
PRINT_INT(sizeof(person));
struct {
char *name;
int age;
char *id;
} anonymous_person;
Person person1 = {.name = "andy", .age = 20};
PRINT_INT(person1.age);
return 0;
}