Re: Some doubts on variable-length array
- From: "Fred Kleinschmidt" <fred.l.kleinmschmidt@xxxxxxxxxx>
- Date: Fri, 31 Mar 2006 15:32:33 GMT
"lovecreatesbeauty" <lovecreatesbeauty@xxxxxxxxx> wrote in message
news:1143799245.354575.50340@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
I can understand the behaviour of these statements marked `/* A. don'tHere foo is being told that tab is an array with dimensions
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])
[size_x][size_y].
It will assume that this is actually the case, regardless of the true size
of the array passed to it in the calling function.
{
printf("tab[1][1] == %d\n", tab[1][1]);
}
if this were void foo( int **tab),
foo would not know the rank of the array
Call function foo, and tell foo that tab is a 2x2 array
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 */Call function foo, and tell foo that tab is a 3x3 array
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 */Error - index out of bounds
printf("%i\n", *(*(tab+3)+3)); /* B. understand */Error - index out of bounds
printf("\n\n");--
return 0;
}
Fred L. Kleinschmidt
Boeing Associate Technical Fellow
Technical Architect, Software Reuse Project
.
- References:
- Some doubts on variable-length array
- From: lovecreatesbeauty
- Re: Some doubts on variable-length array
- From: lovecreatesbeauty
- Some doubts on variable-length array
- Prev by Date: Text mode fseek/ftell
- Next by Date: Globally declared arrays
- Previous by thread: Re: Some doubts on variable-length array
- Next by thread: Re: Some doubts on variable-length array
- Index(es):
Relevant Pages
|