The code:
Code:
#include <stdio.h>
main () {
int size = 5;
int *pointer;
int list[size];
int count = 0;
pointer = list;
for (count = 0; count<25; count++ ) {
if (count == size) {
int previoussize = size;
int counter;
size = size +5;
int newlist[size];
printf("\nlist extended\n\n");
pointer = newlist;
}
*(pointer+count) = count;
printf("%d : %d\n", count, *(pointer+count));
}
printf("\n\n");
int count2 = 0;
for (count2 = 0; count2<25; count2++) {
printf("%d : %d\n", count2, *(pointer+count2));
}
}
the output:
Code:
0 : 0
1 : 1
2 : 2
3 : 3
4 : 4
list extended
5 : 5
6 : 6
7 : 7
8 : 8
9 : 9
list extended
10 : 10
11 : 11
12 : 12
13 : 13
14 : 14
list extended
15 : 15
16 : 16
17 : 17
18 : 18
19 : 19
list extended
20 : 20
21 : 21
22 : 22
23 : 23
24 : 24
0 : 1997992286
1 : 0
2 : 1
3 : 1998596384
4 : 2686460
5 : 1997972546
6 : 1998587072
7 : 2686472
8 : 1997992444
9 : 17
10 : 2686536
11 : 1998046803
12 : 1
13 : 1998596384
14 : 1998046752
15 : -461084764
16 : 2686592
17 : 0
18 : 2686544
19 : 15
20 : 2686492
21 : 21
22 : 2686916
23 : 1998097621
24 : -1816436796
What's happening here?