Home > Article > Backend Development > When referencing an array element in C language, what is the allowed data type of its array subscript?
When referencing array elements in C language, the data type of the array subscript is allowed to be: integer constant or integer expression. C language stipulates that array elements can only be referenced one by one instead of the entire array at once. The representation of data elements is "array name [subscript]", and the subscript can be an integer constant or an integer expression.
The operating environment of this tutorial: windows7 system, c99 version, Dell G3 computer.
When referencing array elements in C language, the data type of the array subscript is allowed to be: integer constant or integer expression.
Tutorial recommendation: "c Language Tutorial Video"
There is only one-dimensional array in the array, and the size of the array must be determined as a constant at compile time. But the elements of a C array can be any type of object, and of course it can also be another array, so a multi-dimensional array is "simulated".
Array name:
Pointer to the element with index 0 in the array.
Array subscript:
C language stipulates that array elements can only be referenced one by one and not the entire array at once. The representation of data elements is "array name [subscript ]", the subscript can be an integer constant or an integer expression.
Any array subscript operation is equivalent to a corresponding pointer operation.
That is: a[i]=*(a i)=*(i a)=i[a]
(The latter writing method is never recommended)
Example:
#include <stdio.h> void main() { int a[20]={0}; *a=66; printf("a[0]: %d \n",a[0]); printf("0[a]: %d \n",0[a]); return; }
The result is:
a[0]: 66 0[a]: 66
The writing is very interesting.
For more programming related knowledge, please visit: Programming Video! !
The above is the detailed content of When referencing an array element in C language, what is the allowed data type of its array subscript?. For more information, please follow other related articles on the PHP Chinese website!