There are several approaches. First, the size of the array can be calculated using the formula sizeof( массива ) / sizeof( элемента массива ) . for example
for ( size_t i = 0; i < sizeof( peremen_t ) / sizeof( *peremen_t ); i++ ) { qDebug() <<"peremen_t[i] " << peremen_t[i]; }
Secondly, you can use a for loop based on a range. If you need an element index, then you can define it before the loop. For example,
size_t i = 0; for ( auto x : peremen_t ) { qDebug() <<"peremen_t[" << i << "] " << x; ++i; }
You can also use a loop with iterators. For example,
#include <iterator> // ... size_t i = 0; for ( auto it = std::begin( peremen_t ); it != std::end( peremen_t ); ++it, ++i ) { qDebug() <<"peremen_t[" << i << "] " << *it; }
And finally, you can write a template function that performs the required task. For example,
template <typename T, size_t N> inline void f( const T ( &peremen_t )[N] ) { for ( size_t i = 0; i < N; i++ ) { qDebug() <<"peremen_t[i] " << peremen_t[i]; } }
In addition, you can use any limit value in the array. For example, for character arrays, this may be '\0' , provided that the actual elements of the array cannot contain this character, or some other unique value. For example,
char peremen_t[] = {10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 0 }; // ^^^ for ( size_t i = 0; permen_t[i] != '\0'; i++ ) { qDebug() <<"peremen_t[i] " << peremen_t[i]; }
количество элементов массива = sizeof(массива)/sizeof(одного элемента массива). - post_zeew