aboutsummaryrefslogtreecommitdiffstats
path: root/test/aarch64/c/array1.c
blob: 5840ca6634191267129f9b4aa32895564f7d4057 (plain)
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
/* array1.c -- Simple operations with arrays.
 */

#include <stdio.h>
#define N 10

void oneWay(void);
void anotherWay(void);

int main(void) {
  printf("\noneWay:\n");
  oneWay();
  printf("\nantherWay:\n");
  anotherWay();
}

/*Array initialized with aggregate */
void oneWay(void) {
  int vect[N] = {1,2,3,4,5,6,7,8,9,0};
  int i;
  
  for (i=0; i<N; i++)
    printf("i = %2d  vect[i] = %2d\n", i, vect[i]);
} 

/*Array initialized with loop */
void anotherWay(void) {
  int vect[N];
  int i;
  
  for (i=0; i<N; i++)
    vect[i] = i+1;

  for (i=0; i<N; i++)
    printf("i = %2d  vect[i] = %2d\n", i, vect[i]);
} 

/* The output of this program is

oneWay:
i =  0  vect[i] =  1
i =  1  vect[i] =  2
i =  2  vect[i] =  3
i =  3  vect[i] =  4
i =  4  vect[i] =  5
i =  5  vect[i] =  6
i =  6  vect[i] =  7
i =  7  vect[i] =  8
i =  8  vect[i] =  9
i =  9  vect[i] =  0

antherWay:
i =  0  vect[i] =  1
i =  1  vect[i] =  2
i =  2  vect[i] =  3
i =  3  vect[i] =  4
i =  4  vect[i] =  5
i =  5  vect[i] =  6
i =  6  vect[i] =  7
i =  7  vect[i] =  8
i =  8  vect[i] =  9
i =  9  vect[i] = 10

 */