A little help with pointers
1
Name:
Anonymous
2011-02-04 15:02
main ()
{
int A[1][2][3][4];
//I put random values in it
G(&A[0][0][0][0]);
}
void G(int *A)
{
cout << A[2][2][3][4];
}
It says me "Invalid type 'int[int]' for array subscript"... Why?
2
Name:
Anonymous
2011-02-04 15:04
Sorry... It's
void G(int *A)
{
cout << A[1][2][3][4];
}
3
Name:
Anonymous
2011-02-04 15:08
try void G(int ****A)
4
Name:
Anonymous
2011-02-04 15:15
Nope. The problem is that if i use, it works...
cout<<*(A+1*2*3*4*sizeof(int)+2*3*4*sizeof(int)+3*4*sizeof(int)+4*sizeof(int))
I read in a book that this code should work, but it doen's work for me.
void G(int *A)
{
int n=A[1][2][3][4];
cout << n;
}
5
Name:
Anonymous
2011-02-04 15:18
It says me "Invalid type 'int[int]' for array subscript"... Why?
Because the 'int[int]' type is invalid as an array subscript.
6
Name:
Anonymous
2011-02-04 15:18
>>4
A is an
int****, see
>>3 .
7
Name:
Anonymous
2011-02-04 15:28
>>6
See what
>>1 is calling it with though.
8
Name:
Anonymous
2011-02-04 15:31
9
Name:
Anonymous
2011-02-04 16:06
void G(int ************************************A)
EXPERT ''FAGOT''
10
Name:
Anonymous
2011-02-04 16:07
It's not an array of arrays of arrays of arrays. Behind the scenes its just a regular 1D array. When you index into the ``subarrays'' the compiler needs to know the dimensions you've specified so that it can figured out the location in the 1D array.
void G(int A[1][2][3][4])
{
}
main ()
{
int A[1][2][3][4];
G(A);
}
11
Name:
Anonymous
2011-02-04 17:11
U MENA
void G(int *A)
{
cout << (*A)[1][2][3][4];
}
12
Name:
Anonymous
2011-02-04 17:26
13
Name:
Anonymous
2011-02-04 17:31
Thanks everybody
14
Name:
Anonymous
2011-02-04 17:32
>>13
No problem. Just be sure to sage your posts in the future
!
15
Name:
VIPPER
2011-02-04 17:38
16
Name:
Anonymous
2011-02-04 17:42
17
Name:
Anonymous
2011-02-04 18:47
18
Name:
Anonymous
2011-02-04 20:04