How do I assign a pointer to an array?
The following code doesn't compile...
int myarr[8][8];
/*
... here i'm filling the array
*/
int *ptrarr;
ptrarr = myarr;
I tried to use the usual form for non-arrays (ptrarr=&myarr) but it also doesn't work... I'm at loss here.
Mario
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2002-05-16
I am having similiar problems with arrays of pointers to pointers (I have posted in programming forum about it) Though i think i can help with the fundementals (I think:)
Since you are using a two dimensional array, you cannot assign a double indirected pointer to a single indirected pointer. In other words, your multi-dimensional array is actually two sets pointers wrapped up into one, its an array of pointers to pointers. So in order to assign the Addresses of your multi-dimensional array into another, you have to double indirect it.
Like this:
int** ptrarr;
ptrarr = myarr;
Its confusing as hell, YES.
I am still trying to get it. . . So dont be angry if i am wrong:)
Good Luck, Sir
Chris Brandt
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2002-05-16
How could I be angry when someone tries to help me :)
Thanks Chris. :)
Mario
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2002-07-10
Hi Mario
This is how it's done:
int myarr[8][8];
/*
... here i'm filling the array
*/
int *ptrarr;
ptrarr = &myarr[0][0]; // note this line!
I hope this helps!
Dave Carter
PS - Give me a shout if you want some more explanation.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2002-11-03
You can find programs in C whith this subjet, but... in Spanish languaje.
They are in "Arrays" folder in the URL:
www.geocities.com/ismaelcamarero
I've also a tutorial about "Pointers " in Tutoriales (PowerPoint file)
Good Luck!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Try posting on comp.lang.c++ or comp.lang.c++.moderated newsgroups. You'll receive answers from professional C++ developers. I've learned a lot browsing those newsgroups.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Try posting on comp.lang.c++ or comp.lang.c++.moderated newsgroups. You'll receive answers from professional C++ developers. I've learned a lot browsing those newsgroups.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
How do I assign a pointer to an array?
The following code doesn't compile...
int myarr[8][8];
/*
... here i'm filling the array
*/
int *ptrarr;
ptrarr = myarr;
I tried to use the usual form for non-arrays (ptrarr=&myarr) but it also doesn't work... I'm at loss here.
Mario
I am having similiar problems with arrays of pointers to pointers (I have posted in programming forum about it) Though i think i can help with the fundementals (I think:)
Since you are using a two dimensional array, you cannot assign a double indirected pointer to a single indirected pointer. In other words, your multi-dimensional array is actually two sets pointers wrapped up into one, its an array of pointers to pointers. So in order to assign the Addresses of your multi-dimensional array into another, you have to double indirect it.
Like this:
int** ptrarr;
ptrarr = myarr;
Its confusing as hell, YES.
I am still trying to get it. . . So dont be angry if i am wrong:)
Good Luck, Sir
Chris Brandt
How could I be angry when someone tries to help me :)
Thanks Chris. :)
Mario
Hi Mario
This is how it's done:
int myarr[8][8];
/*
... here i'm filling the array
*/
int *ptrarr;
ptrarr = &myarr[0][0]; // note this line!
I hope this helps!
Dave Carter
PS - Give me a shout if you want some more explanation.
You can find programs in C whith this subjet, but... in Spanish languaje.
They are in "Arrays" folder in the URL:
www.geocities.com/ismaelcamarero
I've also a tutorial about "Pointers " in Tutoriales (PowerPoint file)
Good Luck!
Try posting on comp.lang.c++ or comp.lang.c++.moderated newsgroups. You'll receive answers from professional C++ developers. I've learned a lot browsing those newsgroups.
Try posting on comp.lang.c++ or comp.lang.c++.moderated newsgroups. You'll receive answers from professional C++ developers. I've learned a lot browsing those newsgroups.