Re: Some doubts on variable-length array



I can understand the behaviour of these statements marked `/* A. don't
understand */' in following code, but do not understand the statements
marked `/* B. understand */' .

The behaviour of the following statements of A kind is different to B
kind.

Thank you.

#include <stdio.h>

void foo(int size_x, int size_y, int tab[size_x][size_y])
{
printf("tab[1][1] == %d\n", tab[1][1]);
}

int main()
{
/* int tab[9] = {0, 1, 2, 3, 4, 5, 6, 7, 8}; */
int tab[3][3] = {0, 1, 2, 3, 4, 5, 6, 7, 8};

foo(2, 2, tab); /* A. don't understand */
printf("%i\n", tab[2][2]); /* B. understand */
printf("%i\n", *(*(tab+2)+2)); /* B. understand */
printf("\n\n");

foo(3, 3, tab); /* A. don't understand */
printf("%i\n", tab[3][3]); /* B. understand */
printf("%i\n", *(*(tab+3)+3)); /* B. understand */
printf("\n\n");

return 0;
}

.