Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Length of Dynamically Created Multidemensional Arrays

Reply
Thread Tools

Length of Dynamically Created Multidemensional Arrays

 
 
GraemeC
Guest
Posts: n/a
 
      05-01-2007
How can you determine the length of a dynamically created
multidimensional array?

Tried using sizeof unsuccesufully. It always returns 4, presumably
becuase I am using ints and it is just telling me the size of the
pointer myArray

Many thanks

G


int ** myArray = 0;
int Rows;
int Cols;

cout << "Number of Rows?" << endl;
cin >> Rows;

myArray = new int*[Rows];

for (int i_r = 0; i_r < Rows; i_r++)
{
cout << "Number of cols?" << endl;
cin >> Cols;

myArray[i_r] = new int[Cols];
for (int i_c=0; i_c < Cols; i_c++) {
cout << "Number" << i_c << endl;
cin >> myArray[i_r][i_c];
}
}
}

return 0;
}

 
Reply With Quote
 
 
 
 
Rolf Magnus
Guest
Posts: n/a
 
      05-01-2007
GraemeC wrote:

> How can you determine the length of a dynamically created
> multidimensional array?


By remembering the size you specified when creating it. Alternatively, use
std::vector instead of an array.

> Tried using sizeof unsuccesufully. It always returns 4, presumably
> becuase I am using ints and it is just telling me the size of the
> pointer myArray


It has nothing to do with int. If you use sizeof on a pointer, you get the
size of a pointer.

 
Reply With Quote
 
 
 
 
pmouse
Guest
Posts: n/a
 
      05-02-2007
To put it simply: You can't.

Therefore, you either store the length somewhere, or you put a marker
at the boundaries of the array.

look for STL's vector type.

Regards,

PQ

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
psl assertion for dynamically created signal length David Belohrad VHDL 1 12-16-2011 10:40 AM
Affecting a dynamically created drop down from another dynamically created drop down. msimmons ASP .Net 0 07-16-2009 03:17 PM
Multidimensional arrays and arrays of arrays Philipp Java 21 01-20-2009 08:33 AM
Managing ViewState of a dynamically created Custom Composite Server Control -(where the original is also dynamically created) dickster ASP .Net Building Controls 0 12-08-2005 09:32 AM
How can I increment/decrement a multidemensional array without a loop? Hendrix C++ 1 06-29-2003 07:59 AM



Advertisments