I found one example in C++ book and can’t understand one line of code – never meet such way of recording before:
#include <cstddef>
int main() {
const size_t n{ 100 };
int v[n];
// ANSI-C
size_t i;
for (i=0; i<n; i++) v[i]=0;
// C99
for (size_t i=0; i<n; i++) v[i]=0;
// C++17
for (auto& x : v) x = 0;
}
Third line, const – constant variable, size_t – data type for array and strings length, but what means n{ 100 } ? Is it n = 100; or ? As far I understand this example, n should define number of array v members, but why it’s wrote that way?
New contributor
Anton Vorobev is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1