I want to make an array whose size is to be determined during run time i.e. user input.
I tried to do it like this:
printf("enter the size of array \n");
scanf("%d",&n);
int a[n];
But this resulted in an error.
How do I set the size of an array like this?
Unless you are using C99 (or newer) you need to allocate memory manually, e.g. using
calloc().If you do have a C99-compliant compiler, e.g. GCC with
--std=c99, your code works fine: