In the course begining it was instructed that while initialising an array we allocate it space that is equal to some maximum range its value can be expeted to go.
This makes sense because we want our code to compile.
e.g int a[1000000]
in actual practise, i have noticed that if we initialise the array with some size n, that we input right before it, at runtime, it still works??
So in a way, im saving spoce by only allocating the required memory right??
e.g. int n;
cin>>n;
int arr[n];
What is wrong with this method? is it correct to use? is there a problem?? why does this work, since we dont even alllocate memory at compile time??
how is this different or better/worse that allocating max range??
why does prateek bhaiya always do the first approach as opposed to the second because it seems less space efficient…
i have had these doubts for a while, please help clear up?
is it a compiler specific thing? if so, how?? im thoroughly confused.
Thanks for your help!