L
lovecreatesbeauty
Hello experts,
I have seen following the code snippet given by Marc Boyer (with slight
changes by me for a better format), and have doubts on it. I am so
grateful if you can give me your kindly help and hints on this problem.
1. Does the function call `foo(3, 3, tab);' refer to the data outside
the array `int tab[9];'. The available subscription for a 3X3 2-D array
should be 0..2 X 0..2, I think.
2. For the available function call `foo(2, 2, tab);' (I do not think
the second one is unavailable, just not sure.), which element in the
array `int tab[9];' does tab[0][0] refer to inside the body of the
function `foo'. I want to know the exact one int the format `tab[0] ..
tab [8]'.
And which element in `int tab[9];' does tab[1][1] refer to.
I can not figure it out for some while on it. The GCC4.1 says it does
not support the variable-length array of C99, but I can compile this
program on even GCC3.3.5, and also on GCC4.1 after I installed this
newest one. I also get the same result of the program as Marc Boyer.
Sincerely,
lovecreatesbeauty
/* sample by Marc Boyer */
#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};
foo(2, 2, tab);
foo(3, 3, tab);
return 0;
}
news> ./a.out
tab[1][1] == 3
tab[1][1] == 4
I have seen following the code snippet given by Marc Boyer (with slight
changes by me for a better format), and have doubts on it. I am so
grateful if you can give me your kindly help and hints on this problem.
1. Does the function call `foo(3, 3, tab);' refer to the data outside
the array `int tab[9];'. The available subscription for a 3X3 2-D array
should be 0..2 X 0..2, I think.
2. For the available function call `foo(2, 2, tab);' (I do not think
the second one is unavailable, just not sure.), which element in the
array `int tab[9];' does tab[0][0] refer to inside the body of the
function `foo'. I want to know the exact one int the format `tab[0] ..
tab [8]'.
And which element in `int tab[9];' does tab[1][1] refer to.
I can not figure it out for some while on it. The GCC4.1 says it does
not support the variable-length array of C99, but I can compile this
program on even GCC3.3.5, and also on GCC4.1 after I installed this
newest one. I also get the same result of the program as Marc Boyer.
Sincerely,
lovecreatesbeauty
/* sample by Marc Boyer */
#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};
foo(2, 2, tab);
foo(3, 3, tab);
return 0;
}
news> ./a.out
tab[1][1] == 3
tab[1][1] == 4