2 <clause number="25.5.3" title="Pointer element access">
3 <paragraph>A <non_terminal where="25.5.3">pointer-element-access</non_terminal> consists of a <non_terminal where="14.5">primary-no-array-creation-expression</non_terminal> followed by an expression enclosed in "[" and "]". <grammar_production><name><non_terminal where="25.5.3">pointer-element-access</non_terminal></name> : <rhs><non_terminal where="14.5">primary-no-array-creation-expression</non_terminal><terminal>[</terminal><non_terminal where="14.14">expression</non_terminal><terminal>]</terminal></rhs></grammar_production></paragraph>
4 <paragraph>In a pointer element access of the form P[E], P must be an expression of a pointer type other than void*, and E must be an expression of a type that can be implicitly converted to <keyword>int</keyword>, <keyword>uint</keyword>, <keyword>long</keyword>, or <keyword>ulong</keyword>. </paragraph>
5 <paragraph>A pointer element access of the form P[E] is evaluated exactly as *(P + E). For a description of the pointer indirection operator (*), see <hyperlink>25.5.1</hyperlink>. For a description of the pointer addition operator (+), see <hyperlink>25.5.6</hyperlink>. </paragraph>
7 <example>[Example: In the example <code_example><![CDATA[
12 char* p = stackalloc char[256];
13 for (int i = 0; i < 256; i++) p[i] = (char)i;
17 ]]></code_example>a pointer element access is used to initialize the character buffer in a for loop. Because the operation P[E] is precisely equivalent to *(P + E), the example could equally well have been written: <code_example><![CDATA[
22 char* p = stackalloc char[256];
23 for (int i = 0; i < 256; i++) *(p + i) = (char)i;
27 ]]></code_example>end example]</example>
29 <paragraph>The pointer element access operator does not check for out-of-bounds errors and the behavior when accessing an out-of-bounds element is undefined. <note>[Note: This is the same as C and C++. end note]</note> </paragraph>