_Countof (Using the GNU Compiler Collection (GCC)) (original) (raw)
6.9 Determining the Number of Elements of Arrays ¶
The keyword _Countof
determines the number of elements of an array operand. Its syntax is similar to sizeof
. The operand must be a parenthesized complete array type name or an expression of such a type. For example:
int a[n]; _Countof (a); // returns n _Countof (int [7][3]); // returns 7
The result of this operator is an integer constant expression, unless the array has a variable number of elements. The operand is only evaluated if the array has a variable number of elements. For example:
_Countof (int [7][n++]); // integer constant expression _Countof (int [n++][7]); // run-time value; n++ is evaluated