Systemnahe Programmierung in C: Felder als Parameter |
1long func1 (long *p);
2long func2 (long a[]);
3
4void
5f (void)
6{
7 long x, a[5];
8
9 x = func1 (a);
10 x = func2 (&a[0]);
11
12}
13
14long
15func1 (long *p)
16{
17 return *(p + 1) + p[2];
18}
19
20long
21func2 (long a[])
22{
23 return a[1] + *(a + 2);
24}
|
1#include <stdio.h>
2
3#define FALSE 0
4#define TRUE 1
5
6void
7bubbleSort (int list[], int len)
8{
9 int sorted = FALSE;
10
11 while (!sorted)
12 {
13 int j;
14 sorted = TRUE;
15 for (j = 0; j < len - 1; j++)
16 {
17 if (list[j] > list[j + 1])
18 {
19 int t;
20 sorted = FALSE;
21 t = list[j];
22 list[j] = list[j + 1];
23 list[j + 1] = t;
24 }
25 }
26 }
27}
28
29int list[] = { 13, 56, 23, 1, 89, 58, 20, 125, 86, 3 };
30
31#define listLength ( sizeof list / sizeof list[0] )
32
33int
34main (void)
35{
36 bubbleSort (list, listLength);
37
38 {
39 int i;
40 for (i = 0; i < listLength; ++i)
41 printf ("list[%d] = %d\n", i, list[i]);
42 }
43
44 return 0;
45}
|
Letzte Änderung: 11.01.2007 | © Prof. Dr. Uwe Schmidt |