-
Notifications
You must be signed in to change notification settings - Fork 0
/
study.c
132 lines (109 loc) · 2.14 KB
/
study.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#include <stdio.h>
#include <stdlib.h>
struct Elf {
int type_code;
int level;
int x;
int y;
int z;
};
struct Human {
int type_code;
int level;
int x;
int y;
int z;
};
int getA(int x) {
return x + 1;
}
int getA2(int* x) {
return *x + 1;
}
long getB(long x) {
return x + 2;
}
float getC(float x) {
return x + 1.1f;
}
double getD(double x) {
return x + 1.111;
}
char getE() {
return 'z';
}
void get_sum_and_product(int x, int y, int* sum, int* product) {
*sum = x + y;
*product = x * y;
}
int main() {
// data types
int x = 1;
int a = getA2(&x);
long b = getB(10);
float c = getC(1.1f);
double d = getD(1.111);
char e = getE();
int salary = 10000;
int array_of_salary[100];
int index = 0;
int* dynamic = malloc(x * sizeof(int));
printf("dynamic : %p\n", dynamic);
int sum = 0;
int product = 0;
get_sum_and_product(2, 3, &sum, &product);
for (index = 0; index < 100; index++) {
array_of_salary[index] = 0;
}
index = 0;
// calculation
int aaa = 1 + 1;
long bbb = 11 + 11;
float ccc = 1.1f + 1.1f;
double ddd = 1.111 + 1.111;
// struct
struct Elf f;
f.level = 1;
f.x = 10;
struct Human g;
g.level = 1;
g.x = 1;
// pointers
int* aa = &a; // address of int
long* bb = &b; // address of long
float* cc = &c; // address of float
double* dd = &d; // address of double
char* ee = &e; // address of char
// pointers of pointer of pointer
int** paa = &aa;
// if
if (salary < 3000) {
salary = salary * 0.95;
} else if (salary == 3000) {
salary = salary * 0.7;
} else {
salary = salary * 0.5;
}
// for
int sigma = 0;
for (index = 1; index < 101; index = index + 1) {
sigma = sigma + index;
}
// while
int max = 100;
while (max < 100) {
max = max + 1;
}
max = 0;
// do - while
do {
max = max + 1;
} while(max < 100);
printf("number : %d %ld %f %f %c\n", a, b, c, d, e);
printf("Elf level : %d\n", f.level);
printf("pointers : %p %p %p %p %p\n", &a, &b, &c, &d, &e);
printf("pointer : %p\n", aa);
printf("pointer to pointer : %p\n", &aa);
printf("pointer to pointer : %p\n", paa);
return 0;
}