Let me take an example to explain my problem,
Case I
#include<iostream>
using namespace std;
int main(){
int n;
cin>>n;
int a[n];
for(int i=0;i<n;i++)
cin>>a[i];
}
Case II
#include<iostream>
using namespace std;
int main(){
int n;
cin>>n;
int *a = new int[n];
for(int i=0;i<n;i++)
cin>>a[i];
}
Correct me if I am wrong, to my understanding, Case I falls under static memory allocation domain and Case II falls under dynamic memory allocation domain. So if I am able to achieve the same functionality by static memory allocation, why use dynamic.
In both the above cases, I am able to achieve the same functionality, but why is Case I considered bad and Case II the correct way.
The only difference in both the codes is line number 6.