-
September 28th, 2003, 07:08 AM
#1
Junior Member
Pointers to Multidimensional Arrays
Hi there,
I have a problem that I can't seem to resolve. I know that if we have, say, an integer array A[5], then we can initialise a pointer to an integer as follows:
int* B = A;
But I can't seem to figure out what kind of pointer can be initialised to the name of a multidimensional array. For instance, if I have A[5][5], and I want to initialise B to A:
X B = A;
what should X be?
Thanks a lot for your help.
Sincerely,
shred2er.
-
September 28th, 2003, 10:25 AM
#2
Junior Member
well ,
it should be
int *B=A
this will store the base address that is the starting address of array A ,the 2-d array are stored as linear array internally
-
September 28th, 2003, 04:36 PM
#3
Junior Member
Hi vanika,
Thanks for the response. I had already tried that before posting, but unfortunately it does not work.
In my program I have defined an array A[3][3]. Then I tried to initialise a pointer to an integer B as follows: int* B = A. The compile-time error is:
MatrixOperations.C: In function `int main (int, char **)':
MatrixOperations.C:50: cannot convert `int (*)[3]' to `int *' in
initialization
I have also tried int** B = A. There is noe that does not give any compile-time error: int* B = A[5]. But dereferencing B does not produce the desired results.
But I thank you for your trouble. Perhaps you have some other ideas as well?
Sincerely,
shred2er.
-
September 28th, 2003, 05:02 PM
#4
int (*B)[3] = A
if I remember correctly, its been a long time
\"Ignorance is bliss....
but only for your enemy\"
-- souleman
-
September 28th, 2003, 09:33 PM
#5
Member
Try specifying to the pointer that it has to point to the first element in the array.
For example
int A[2][2];
int*C;
C=&A[0][0];
tell me if it gives you any errors
I Speak in frequencies even dogs have trouble hearing
-
September 28th, 2003, 11:18 PM
#6
Junior Member
Originally posted here by Q-bel
Try specifying to the pointer that it has to point to the first element in the array.
For example
int A[2][2];
int*C;
C=&A[0][0];
tell me if it gives you any errors
Woohoo! Thanks, Q-bel! It works!
-
September 29th, 2003, 02:25 AM
#7
Member
No problem man just as they've been helping me learn here I gotta try and help out at least in what I can jeje.
I Speak in frequencies even dogs have trouble hearing
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|