Expression must have a constant value c++ string length.
Cause of error expression must have a constant value c++ string length.
Having a constant value c++ string length is a must for this error expression which comes when a user tries to expatiate what an array of c++ is.
This is a common problem which have many solutions. It is as thus;
We used Array to store many values in a single variable as opposed to having separate variables for each value.
Declaration of an array have to do with specifying the variable type, the enclosure of the array’s name is done in a square brackets, and amount of number it should hold: vehicles on a string .
Before building it, the array’s size must be fixed. A dynamically sized array must have memory allocated for it on the heap. Once the use is completed, it must be released with delete.
//allocate the array
into** are= new int * [row] ;
for (int i = 0 ; i < row: i++)
arr [i] = new int [ col ] ;
//use the array
//deallocate the array
for (int i = 0 ; i < row ; i ++)
delete [ ] arr [ i ] ;
delete [ ] arr ;
For a fixed size array, it’s a must to declare constant.
const int row = 8 ;
const int col = 8 ;
int arr [ row ] [ col ];
According to the standard, the length of the array should be a number that can be calculated at build time in order for the compiler to allocate adequate space on the stack. In this stance, you’re attempting to set the length of the array that is not known at compile time. Non-constant variables contents is the one to assume the compiler.
const int row =8;
const int col = 8;
int a [ row ] [ col ];