Archived

This topic is now archived and is closed to further replies.

how to use sizeof(..)?

This topic is 5780 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Thank you, i know how to use vector on MSDN now.

However, beside the vector, do i have another way to know the size of the **num?

why it can work?

int num[10]={0};
sizeof(num); //it display 40

Share this post


Link to post
Share on other sites
None that you'd want to use, short of writing your own memory allocation routines.

Edit: I amend that. You can allocate one extra pointer, set it to NULL, then walk and count trough your int* array until you reach NULL. strlen() works similarly.

Edited by - Fruny on February 16, 2002 2:28:35 AM

Share this post


Link to post
Share on other sites
For dynamic pointers, sizeof returns 4, always. For static pointers, it returns the total size of the array.

short Static [10];
sizeof(Static) == 20

short* Dynamic = new short [10];
sizeof(Dynamic) == 4


~CGameProgrammer( );

Share this post


Link to post
Share on other sites
quote:
Original post by CGameProgrammer
For dynamic pointers, sizeof returns 4, always. For static pointers, it returns the total size of the array.

short Static [10];
sizeof(Static) == 20

short* Dynamic = new short [10];
sizeof(Dynamic) == 4



And

short* Foo = Static;
sizeof(Foo) == 4

Share this post


Link to post
Share on other sites