Re: [Dev-C++] How to get the number of elements in an array
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Per W. <pw...@ia...> - 2004-01-20 13:41:14
|
In short - you can't.
sizeof(Buf) will return sizeof(int*) i.e. the size of a pointer.
There is no way of requesting the size of a dyanmically allocated array.
You must store the size somewhere else, such as:
struct {
int size;
int *ptr;
} Buf;
Buf.size = 9;
Buf.ptr = new int[Size];
/Per W
On Tue, 20 Jan 2004, Daniel Glenfield wrote:
> This is an easy Q I know but I can't think how to do it...
>
> Size = 9; // Decided by a function but set to 9 for this example
>
> int* Buf = new int[Size];
>
> int Tmp = sizeof(Buf);
>
> This can't be right. How do I get the size? Len(Buf) and Length(Buf) are not
> recognised (I thought they were functions but I guess not).
>
> Any thoughts?
>
> _________________________________________________________________
> Use MSN Messenger to send music and pics to your friends
> http://www.msn.co.uk/messenger
>
>
>
> -------------------------------------------------------
> The SF.Net email is sponsored by EclipseCon 2004
> Premiere Conference on Open Tools Development and Integration
> See the breadth of Eclipse activity. February 3-5 in Anaheim, CA.
> http://www.eclipsecon.org/osdn
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
|