CKTIS / C++
Array declarator: T name[N]
T name[N] declares a built-in array of N elements of type T. Its bound must be a positive compile-time constant; the elements occupy contiguous storage.
Version: C++23; repository compiler flag, production runtime not attested
Syntax
T name[N];In T name[N];, T is the element type, name is the array name, and N is the element count, not the last index. Elements occupy contiguous storage and have indices from 0 to N - 1.
N must be a converted constant expression of type std::size_t with a value greater than zero. A size read at runtime does not meet this requirement. The element type cannot be a reference type, function type, void, or array of unknown bound.
The initializer {4, 5, 6} supplies successive values. In int values[] = {4, 5, 6};, the bound is deduced from the initializer. In a declaration, [] describes an array; in the expression values[0], it selects an element.
The example uses constexpr int N = 3 and prints the first and last elements and their array's total. The expected output is 4 6 15 followed by a newline. The sources are the current working draft, not a frozen C++23 text.
Examples
#include <iostream>
int main() {
constexpr int N = 3;
int values[N] = {4, 5, 6};
int total = 0;
for (int value : values) {
total += value;
}
std::cout << values[0] << ' ' << values[N - 1]
<< ' ' << total << '\n';
}
Result
4 6 15
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.