C++ Array Initialization
There are two ways to initialize arrays in C++:
• Static initialization: is used to initialize arrays at compile time. This can be done by explicitly listing the initial values of the array elements, or by using an initializer list.
• Dynamic initialization: Dynamic initialization is used to initialize arrays at runtime. This is done using the new operator to allocate memory for the array, and then assigning values to the array elements.
Here is an example of how to initialize an array using static initialization:
This code declares an array called my_array with 5 elements. The array is initialized with the values 1, 2, 3, 4, and 5.
This code is equivalent to the previous example. The initializer list is used to initialize the array elements.
#30DaysOFCreative