Archived

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

wah_on_2

how to use sizeof(..)?

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