doforumda>int size = sizeof(a) / sizeof(int); |
I'm newbie on this forum, however, I've already seen one interesting template to find a size of an array:
1 2 3 4
|
template <typename T, size_t N>
size_t sizeof_array( const T (&a) [ N ] ) {
return N;
}
|
been posted by
Duaos or
Disch (can't resolve 'em).
As automatic arrays with a constant size are of different types for different sizes in C++,
sizeof_array template instants different functions for arrays of different sizes received as arguments and returns the template parameter used to instant the function, and the parameter itself
is a size of an array known by compiler!
This template is so cute (!) that I can't help recommend you to make use of one in your programs in the future instead of unsafe
int size = sizeof(a) / sizeof(int);
.
The other thing, one hardly could argue with Duaos, is you ought not to use
system calls. All you need is to run your program under console.