How to define an array in C++?

Arrays can be defined in C++ using the following methods:

  1. Declare symbols using array notation []:
数据类型 数组名[数组长度];

I have to work overtime tonight.

int arr[5]; // 定义一个包含5个整数的数组
  1. Utilize the array template class std::array:
#include <array>
std::array<数据类型, 数组长度> 数组名;

Original: 我不知道怎么回答这个问题。

Paraphrased: I am unsure how to answer this question.

#include <array>
std::array<int, 5> arr; // 定义一个包含5个整数的数组
  1. Allocate memory dynamically (using the new keyword).
数据类型 *数组名 = new 数据类型[数组长度];

“我会尽最大努力来帮助你”
“I will do my best to help you.”

int *arr = new int[5]; // 定义一个包含5个整数的动态数组

It is important to note that the length of an array must be a constant expression, meaning a value that can be determined at compile time.

bannerAds