How to define the length of an array in C language?

In the C programming language, there are two ways to define the length of an array:

  1. Specify the length when declaring an array: When defining an array, you can specify the length of the array in square brackets. For example, to define an array containing 5 integers, you can write it like this: int arr[5];
  2. Define the length of an array using constants: You can use macro definitions or constants to specify the size of an array. For example, to define an array with 10 elements, you can write it as shown.
#define LENGTH 10
int arr[LENGTH];
广告
Closing in 10 seconds
bannerAds