When I run this code, the printf() function seems to give a random large number, as if it is calling an array that is out of bounds. What is going on here?
#include <stdio.h>
#include <math.h>
int main(void)
{
int test_num = 1000;
int factors[16];
for(int i = 1, j = 0; i < test_num; i++, j++) {
if(test_num % i == 0)
factors[j] = i;
}
printf("%d", factors[2]);
return 0;
}
factors[2]was ever assigned?jin lockstep withi, not in theifstatement.int factors[16];toint factors[16] = {0};in order to initialize the array elements to zero.jis 2,iis 3.1000 % 3 != 0, so j[2] is never assigned to.