I have the following declaration:
char ***a; a = new char**[1]; a[0] = new char*[2]; a[0][0] = "Dynamic"; a[0][1] = "Array"; Now I need to find the number of elements in "a" as well as in "a[0]". How can I do this in C or C++?
I have the following declaration:
char ***a; a = new char**[1]; a[0] = new char*[2]; a[0][0] = "Dynamic"; a[0][1] = "Array"; Now I need to find the number of elements in "a" as well as in "a[0]". How can I do this in C or C++?
As far as I know there is no way to find number of elements in dynamically allocated array, when you pass the first element of the array as pointer to some function/method. Best practice is to avoid usage of such arrays, and when you use it, pass the number of allocated elements together with the pointer.
void doSomething(int * p, int elms) { //... } int main(){ int * arr = new int[10]; doSomething(arr, 10); }