You cannot make a variable constant at runtime.
You can change the value of a constant variable
but this won't help. Look at this mini program:
main()
{
const c = 1, *p = &c;
int * q = const_cast<int *>(p);
*q = 10;
char a[c] = {0}; // q == 10 but sizeof a == 1
return 0;
}
When the array is defined, the value of c is 10,
but the size of the array is one anyway.
To create a dynamic array you have to use the new
operator:
main()
{
int n = 10;
char * a = new char[n]; // create array
a[0] = 1;
a[1] = 2; // ...
delete[] a; // free memory
return 0;
}
Hope this helps.
-- ralf