Step by step

My diary

...

Search

breakinformation. Powered by Blogger.

2018년 9월 26일 수요일

struct initialize


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
#include <stdio.h>
 
struct Phone {
    
    int areacode;
    unsigned long long int number;
};
 
struct Person {
    
    char* name;
    int age;
    struct Phone phone;
};
 
int main(void) {
    
    struct Person person1 = {
    person1.name = "Karma", person1.age = 30
        {
            person1.phone.areacode = 82, person1.phone.number = 3045671234
        }
    };
    
    printf("%d %llu\n", person1.phone.areacode, person1.phone.number);
    
    struct Person person2 = {
    person2.name = "mike", person2.age = 35
        {
            person2.phone.areacode = 82, person2.phone.number = 3012341596
        }
    };
    
    printf("%d %llu\n", person2.phone.areacode, person2.phone.number);
    
    person1.name = "Ari";
    person1.age = 20;
    person1.phone.areacode = 82;
    person1.phone.number = 4575164285;
    
    printf("%s %d %d %llu\n", person1.name, person1.age, person1.phone.areacode, person1.phone.number);
    
    return 0;
}
cs

0 개의 댓글:

댓글 쓰기