sizeof( variable name );
sizeof( data_type_name );
sizeof is a handy tool in finding out the amount of elements in an array:
const int SIZE = sizeof( array ) / sizeof( element_type );
or
const int SIZE = sizeof( array ) / sizeof( array[ 0 ] );
When the value of size is always equal to the actual amount of elements in the array even if the size of the array is changed between complications.
Note that sizeof does not produce a correct answer if they array is a formal parameter of a function.
Reference: cppreference, space, msdn
No comments:
Post a Comment