Square bracket or parenthesis when dealing with the element of an array

When dealing with the element of an array, it seems that both the square bracket a[i] and the parenthesis a(i) are OK. For example,

real[int] U = 1:5;
for (int i = 0; i < U.n; i++ ) {
    cout << U(i) << endl;
}
real[int] U = 1:5;
for (int i = 0; i < U.n; i++ ) {
    cout << U[i] << endl;
}

Which one is preferred, since both can be found in the discussions in the community.

They are the same, pick the one your prefer.

1 Like