/* 01 */ /* alisotku.c */ /* 02 */ /* Mitä ohjelma tulostaa?? */ /* 03 */ #include <stdio.h> /* 04 */ /* 05 */ int a,b,c; /* 06 */ /* 07 */ void ali_1(int *a, int b) /* 08 */ { /* 09 */ int d; /* 10 */ d = *a; /* 11 */ c = b + 3; /* 12 */ b = d - 1; /* 13 */ *a = c - 5; /* 14 */ } /* 15 */ /* 16 */ void ali_2(int *a, int *b) /* 17 */ { /* 18 */ int c; /* 19 */ c = *a + *b; /* 20 */ *a = 9 - c; /* 21 */ *b = 32; /* 22 */ } /* 23 */ /* 24 */ int main(void) /* 25 */ { /* 26 */ int d; /* 27 */ a=1; b=2; c=3; d=4; /* 28 */ ali_1(&d,c); /* 29 */ ali_2(&b,&a); /* 30 */ ali_1(&c,3+d); /* 31 */ printf("%d %d %d %d\n",a,b,c,d); /* 32 */ return 0; /* 33 */ }Seuraavassa g.c täytyy tulkita: globaali muuttuja c ja m.d: main- funktion muuttuja d.
globaalit |
main |
ali_1 |
ali_2 |
laskuja | |||||||
|
|
|
|
|
* |
|
|
* |
* |
|
|
lause |
a |
b |
c |
d |
a |
b |
d |
a |
b |
c |
|
27 a=1; b=2 |
1 |
2 |
3 |
4 |
|
|
|
|
|
|
|
28 ali_1(&d |
|
|
|
|
&m.d |
3 |
? |
|
|
|
ali_1(&m.d,3) |
10 d = *a; |
|
|
|
|
|
|
4 |
|
|
|
= m.d = 4 |
11 c = b+3; |
|
|
6 |
|
|
|
|
|
|
|
= 3+3 = 6 |
12 b = d-1; |
|
|
|
|
|
3 |
|
|
|
|
= 4-1 = 3 |
13 *a= c-5; |
|
|
|
1 |
<-o |
|
|
|
|
|
m.d = g.c-5 = 6-5 = 1 |
29 ali_2(&b |
|
|
|
|
|
|
|
&g.b |
&g.a |
? |
ali_2(&g.b,&g.a) |
19 c =*a+*b |
|
|
|
|
|
|
|
|
|
3 |
= g.b+g.a = 2+1 = 3 |
20 *a= 9-c; |
|
6 |
|
|
|
|
|
<-o |
|
|
g.b = 9-3 = 6 |
21 *b= 32; |
32 |
|
|
|
|
|
|
|
<-o |
|
g.a = 32 |
30 ali_1(&c |
|
|
|
|
&g.c |
4 |
? |
|
|
|
ali_1(&g.c,3+1) |
10 d = *a; |
|
|
|
|
|
|
6 |
|
|
|
= g.c = 6 |
11 c = b+3; |
|
|
7 |
|
|
|
|
|
|
|
= 4+3 = 7 |
12 b = d-1; |
|
|
|
|
|
5 |
|
|
|
|
= 6-1 = 5 |
13 *a= c-5; |
|
|
2 |
|
<-o |
|
|
|
|
|
g.c = c-5 = 7-5 = 2 |
31 printf(" |
|
|
|
|
|
|
|
|
|
|
Tulostus: 32 6 2 1 |
32 return 0 |
|
|
|
|
|
|
|
|
|
|
========= |
/* 01 */ /* alisotk2.c */ /* Mitä ohjelma tulostaa?? */ /* 02 */ #include <stdio.h> /* 03 */ /* 04 */ int b,c; /* 05 */ /* 06 */ void s_1(int *a, int b) /* 07 */ { /* 08 */ int d; /* 09 */ d = *a; /* 10 */ c = b + 3; /* 11 */ b = d - 1; /* 12 */ *a = c - 5; /* 13 */ } /* 14 */ /* 15 */ void a_2(int *a, int &b) /* 16 */ { /* 17 */ c = *a + b; /* 18 */ { int c; c = b; /* 19 */ *a = 8 * c; } /* 20 */ b = 175; /* 21 */ } /* 22 */ /* 23 */ int main(void) /* 24 */ { /* 25 */ int a,d; /* 26 */ a=4; b=3; c=2; d=1; /* 27 */ s_1(&b,c); /* 28 */ a_2(&d,a); /* 29 */ s_1(&d,3+d); /* 30 */ printf("%d %d %d %d\n",a,b,c,d); /* 31 */ return 0; /* 31 */ }