i need a few explanation on array of pointers and more precisly, how to declare them.
Take a look at this code:
main()
{
int array[] = {5, 4, 2};
int array2[] = {6, 8};
int* int_arrays[2] = {array, array2}; // It works!
// int* int_arrays2[2] =
// {
// {5, 4, 2},
// {6, 8}
// };
//
int i, j;
for(i = 0; i < 2; i++)
{
for(j = 0; j < 3; j++) // This loop print a garbage value at the end, no big deal.
printf("%d\n", int_arrays[i][j]);
}
}
For me the commented declartation means the same as the one above. But it doesn't work.
The visual studio C compiler give me those indications:
error: too many initializers.
warning: int* differs in levels of indirection from int.
I guess it means that int array[] = {5, 4, 2}
is something valid to assign to an int*
while {5, 4, 2}
is not.
Could you show me a way to delcare my array of pointer correctly?