Hello everyone,
Here's my code for making a dynamic array(the user inputs the size of the array). It's working fine but I think that I've not made the best code. Is there any suggestion for improvement or optimization?
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
int *p;
int n,i;
printf("how many integers do u wanna enter\n");
scanf("%d",&n);
p=malloc(n*sizeof(int));
for(i=0;i<n;i++)
{
printf("enter the %d element",i+1);
scanf("%d",p);
p++;
}
p=p-n;
for(i=0;i<n;i++)
{
printf("%d\n",*(p+i));
}
free(p);
}