why use malloc function when we can write the code in c like this :
int size;
printf("please the size of the array\n");
scanf("%d",&size);
int arr[size];
this eliminates the possibility of assigning garbage value to array size and is also taking the size of the array at run time ...
so why use dynamic memory allocation at all when it can be done like this ?
scanf:if (scanf("%d",&size) != 1) /* error */;mallocfails you have a chance to handle that error, and it will be portable. Anything related to VLA failure can only be very platform specific.