I've been working the the Kernighan/Ritchie C Programming Language book (2nd edition) and in the example in chapter 1.6, page 22 I've encountered some strange (to me at least) behaviour based on a mistake I made.
The mistake was that I declared int ndigit[10]
but missed the for loop that set all the integers in the array to zero.
The strange thing is the first 8 values in the array seem to work correctly, defaulting to 0, but the last two default to -373429304 and 32766. This resulted in the digit counting function in the program to work as intended apart from the counts of 8s and 9s.
I worked out my mistake and fixed it, but I'm still curious as to why the first 8 values set to 0 but the last two were wildly different?