int x; int array[x];
is prohibited. The advantages of this sort of array usage are that the stack would not be complicated, the function call would not be expensive and the program would run faster.However that doesn't mean that the Dynamic Array is impossible in C. The Dynamic Memory could be used to implement this function:
void main()
{
int *ptr = NULL;
int arr_size;
printf("Enter the size of array : ");
scanf("%d",&arr_size);
ptr = (int*) malloc(arr_size*(sizeof(int));
}
After this you can use
ptr[0],ptr[1],.....ptr[n]
as an array.References: GeekInterview.com C programming interview questions 69 of 437
No comments:
Post a Comment