I'm trying to print a multiplication table that is stored in a 2D array by using pointers to pointers. When I run this code, it only prints out the "1s" column. If I remove the outer loop's incrementation and the line break conditional, then it will print the numbers 1-10 ten times. I don't understand this behavior.
printf("\n");
printf("Multiplication Table in standard array syntax\n");
int a[10][10];
int j;
int k;
int prod;
for (j = 1; j < 11; j++){
for (k = 1; k < 11; k++){
prod = j*k;
a[j - 1][k - 1] = prod;
printf("%d ", a[j - 1][k - 1]);
if (k == 10)
printf("\n");
}
}
printf("\n");
printf("Multiplication Table in standard + pointer syntax\n");
int *pi[10];
int x;
for (x = 0; x <10; x++){
pi[x] = a[x];
}
int y;
for (x = 0; x < 10; x++){
for (y = 0; y < 10; y++){
printf("%d ", *(pi[x] + y));
if (y == 9)
printf("\n");
}
}
printf("\n");
printf("Multpilication Table in pure pointer syntax\n");
int **ppi;
ppi = pi;
int p;
int q;
for (p = 0; p < 10; p++){
for (q = 0; q < 10; q++){
printf("%d", *(*ppi + q));
if (q = 9)
printf("\n");
}
ppi++;
}
}