Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can an array be declared as a constant?

Tags:

People also ask

Is array constant or variable?

So as you can see arrays are memory location, thus you can initialize them and make them constants or you can use them as variables.

How do you assign an array to constant?

In C#, use readonly to declare a const array. public static readonly string[] a = { "Car", "Motorbike", "Cab" }; In readonly, you can set the value at runtime as well unlike const.

Is array a constant in C?

it's a constant array of integers i.e. the address which z points to is always constant and can never change, but the elements of z can change.

Can you make a constant array C++?

In C++, the most common way to define a constant array should certainly be to, erm, define a constant array: const int my_array[] = {5, 6, 7, 8};


Is it possible to either:

  1. Declare an array as a constant

    OR

  2. Use a workaround to declare an array that is protected from adding, deleting or changing elements, and therefore functionally constant during the life of a macro?

Of course I could do this:

Const myConstant1 As Integer = 2 Const myConstant2 As Integer = 13 Const myConstant3 As Integer = 17 Const myConstant4 ...and so on 

...but it loses the elegance of working with arrays. I could also load the constants into an array, and reload them each time I use them, but any failure to reload the array with those constant values before use could expose the code to a "constant" value that has changed.

Any workable answer is welcome but the ideal answer is one that can be setup once and not require any changes/maintenance when other code is modified.