Jump to content
  • Advertisement
Sign in to follow this  
jolyqr

The table elements number

This topic is 4582 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

Advertisement
If you have a array

char array[32];

You can get the size like this

sizeof(array)

However, if you make a pointer to the array

char* parray = array;

and do this

sizeof(parray)

you will get the size of the pointer, not the array.

If you need to send an array as a function argument, the common way to do it is
to send the size of the array as well:

void my_func(char *array, int array_size)

If you have a array of ints, int array[32], you would have to get the size like this:

sizeof(array) / sizeof(int);

This is cumbersome at best. You should probably use a C++ vector instead:

vector<int> vec;

add a integer to the vector

vec.push_back(3);

and get the number of elements like this

vec.size();

To send the vector as an argument to a function, the prefered way to do it is

With write access:
void my_func(vector<int>& vec)

Without write access:
void my_func(const vector<int>& vec)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!