What is the difference?

int n;
cin >> n;

What is the differece since both are of size n given by the user as input?

int a[n];

int *a = new int[n];

This means that a is a pointer which is pointing at the starting of the int array index, this is known as dynamic allocation.

a[0] a[1] a[2] a[3] a[4] a[5]
 ^
 |
*a

whereas this means that

a is the array of size n of int data type, this is known as static allocation.(if instead of variable, a fixed value is being provided like a[100] or any other value).

In the case of

we’re taking n as input from user then we dont know what is the size of the array a, Does it considered as static allocation?

No, as the user can enter any digit equal to or less then 100000, so it won’t be static.
If user enters any value of n after compilation of the program, it’s dynamic allocation. Whereas if he enters any value before compilation of a program it’s static.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.