|
From: Ioannis V. <no...@ho...> - 2002-07-31 15:09:15
|
<http://run.to/noicys> -----Original Message----- From: dev...@li... [mailto:dev...@li...] On Behalf Of Ramana Kumar Sent: Wednesday, July 31, 2002 3:36 PM To: Carlos Garc?a del Monte; C++ Subject: RE: [Dev-C++] sizeof array thank you carlos i had in fact thought of using a special array member at the end, and thank you for illustrating implentation of this so beautifully. i'm afraid this may have to be the way i do it in the end, unless i simply don't pass the array and declare it locally. Or use vector: #include <iostream> #include <vector> void f(std::vector<std::vector<int> >&array) { using namespace std; cout<<array.size()<<endl; } int main() { using namespace std; /// 2-dimensional 100x50 int array initialised to 0 vector<vector<int> >arr(100, vector<int>(50)); f(arr); } but since the array is in fact a two-dimensional array full of instances of my own String class, adding a "terminating character" will involve creating too much arbitrary code for my liking. I am still dreaming of the possibility of sizeof-ing the array with the built in operator, if anyone knows how to do this correctly. In fact, i am highly curious about the workings of the sizeof operator. I realize that since passing an array to a function is actually passing a pointer to the first object ( is this x[0] or x[0][0] in a multidimensional array?), x[0] and &x[0][0] the sizeof operator gets the size of that pointer... or does it? what are you passing the operator when the array is local? When the array is local and you pass the array's name you pass the array. A function can accept only a pointer to the first object or a reference, so in the function you pass the pointer variable (which points to the first element of the array). As a result you get the size of the pointer variable itself. Ioannis * Ioannis Vranos * Programming pages: http://www.noicys.cjb.net <http://www.noicys.cjb.net/> * Alternative URL: http://run.to/noicys |