Home  >  Article  >  Backend Development  >  How to define an array in c++

How to define an array in c++

王林
王林Original
2020-06-19 14:42:5313034browse

How to define an array in c++

If you want to declare an array in C, you need to specify the type of elements and the number of elements, as follows:

type arrayName [ arraySize ];

arraySize must be an integer greater than zero Constant, type can be any valid C data type.

(Recommended tutorial: C Language Tutorial)

For example, to declare an array balance of type double containing 10 elements, the declaration statement is as follows:

double balance[10];

Now balance is an available array that can hold 10 numbers of type double.

Specific elements in an array can be accessed by index. All arrays are composed of contiguous memory locations. The lowest address corresponds to the first element, and the highest address corresponds to the last element.

The above is the detailed content of How to define an array in c++. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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