Home > Backend Development > C#.Net Tutorial > When referencing an array element in C language, what is the allowed data type of its array subscript?

When referencing an array element in C language, what is the allowed data type of its array subscript?

青灯夜游
Release: 2022-12-30 11:12:23
Original
17021 people have browsed it

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.

When referencing an array element in C language, what is the allowed data type of its array subscript?

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;
}
Copy after login

The result is:

a[0]: 66
0[a]: 66
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template