How do I reliably get the size of a C-style array? The method often recommended seems to be to use sizeof
, but it doesn\'t work in the foo
function
You need to pass the size along with the array, just like it is done in many library functions, for instance strncpy()
, strncmp()
etc. Sorry, this is just the way it works in C:-).
Alternatively you could roll out your own structure like:
struct array {
int* data;
int size;
};
and pass it around your code.
Of course you can still use std::list
or std::vector
if you want to be more C++ -ish.