-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathfull_example.c
61 lines (59 loc) · 1.22 KB
/
full_example.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
// program: declarations statements RETURN SEMI functions
// main function (declarations statements)
// declarations
int i; // simple variable
char c = 'c'; // one with init
double val = 2.5, res[6]; // two variables, one with init and one array
double *p; // pointer variable
// statements
p = &res; // assigment
for(i = 0; i < 10; i++){ // for
if(i > 5){ // if-else
break;
}
else if(i == 5){
i = 2 * i;
val = func1();
*p = add(val, i);
print(res[i]);
print("\n");
continue;
}
else{
*p = add(val, i);
val = res[i];
print(res[i]);
print("\n");
p = p + 1;
}
if(i == 2 && val == 4.5){ // if
print("iteration: 3\n");
}
}
while(i < 12){ // while
print(i);
print(" ");
func2(c);
i++;
}
print("\n");
return; /* RETURN SEMI */
// other functions (functions)
int func1(){ /* without parameters */
// statements
return 5;
}
void func2(char c){ /* with one parameter */
// declarations
char *s;
// statements
*s = c;
print(*s);
}
double add (double a, int b){ /* with two parameters */
// declarations
double res;
// statements
res = a + b;
return res;
}