Looping thorugh char array q

Can someone explain why the few lines of code below produce the following output

output:
1
2
3
//the next 4 lines are what baffle me
70
24
-100
16

1
2
3
4
5
 char  myS[] = {'1', '2','3'};
int sum=0;
int i=0;
while(myS[i] != '\0')
cout << myS[i++] -48 << endl;


i know it's easy enough to do a similar loop using the string class ...just curious what's going on here.
Last edited on
Line 4: The array is not nul-terminated, so the condition may or may not trigger at the actual end of the array. The last 4 lines are evidence of buffer overflow.
thank you.
Topic archived. No new replies allowed.