Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
C++ では、ランタイム変数を使用して配列のサイズを宣言できないことは知っていますが、次のことが有効かどうかを確認することに関心があります。
#include directives const int SIZE=5; double a[SIZE];
ありがとうございました!!
はい、C++ と C の両方で合法です。
SIZEは定数式である必要があり、C++ ではconst int SIZE=5;そのように宣言されています。 C99 で可変長配列が導入される前の C では、
SIZE
const int SIZE=5;
const int SIZE=5; double a[SIZE];
この場合SIZE、 は定数式ではなく単に読み取り専用であり、有効であるためには定数式である必要があるため、エラーが発生します。