void main()
{
int *a, c, a1[] = { 1, 2, 3, 4, 5 }, a2[] = { 6, 7, 8, 9, 10 };
cin >> c;
if(c == 1)
a = a1;
else if(c == 2)
a = a2;
for(; *a != NULL; a++)
cout << *a << endl;
}
1
1<-inputted
1<-starting to display array elements
2
3
4
5
1<-extra element (i think it is that inputted value)
2<-inputted two (ignore)
6
7
8
9
10
1<-elements in first array is also included
2
3
4
5
2<-inputted 2 is also displaying as element
You're assuming the array's end in null... you're just printing the entire memory from whatever array you start until you find NULL through luck.
Interestingly enough, you now know the structure of the memory of your program.