How is it possible to pass an array parameter to a function, and calculate the size of the array parameter? Because every time i try to calculate it, the return value is always 4.
Thanks the fast replies. I’m going to pass the size of the array as well then. Or i give a shot to vectors. Thanks
This is (one of) the difference between arrays and pointers. Taking the size of an array results in its size in bytes, whereas taking the size of a pointer yields the size of pointers on that system. However, whenever you pass an array to a function, it decays to a pointer, the size of which is always the same no matter what type of pointer it is (4 on a 32 bit machine).
So technically, it’s impossible to pass an array into a function since whenever you try, it becomes a pointer.
You’ll need to pass the size of the array in to the function as well, or better yet if you can, use
std::vectororstd::array, orstd::stringif you’re using the array as a C-style string.