How can I set an array's size at run time?

Answer Posted / vinod

C99 and above supports the conceptof VLA(Variable Length Array) which allows you to set array size based on input during run time. It can also done using dynamic memory allocation.

Example:
int main()
{
int i;
scanf("%d",&i);
int a[i];
}

Is This Answer Correct ?    1 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is hashing in c language?

615


Explain how can you restore a redirected standard stream?

592


Why is event driven programming or procedural programming, better within specific scenario?

1955


what is recursion in C

616


The statement, int(*x[]) () what does in indicate?

647






Explain with the aid of an example why arrays of structures don’t provide an efficient representation when it comes to adding and deleting records internal to the array.

2655


in multiple branching construct "default" case is a) optional b) compulsarily c) it is not include in this construct d) none of the above

635


What is external variable in c?

613


i = 25;switch (i) {case 25: printf("The value is 25 ");case 30: printf("The value is 30 "); When the above statements are executed the output will be : a) The value is 25 b) The value is 30 c) The value is 25 The value is 30 d) none

647


What is the use of volatile?

610


Explain what is the difference between a free-standing and a hosted environment?

635


What is #include conio h?

596


Who developed c language?

642


Is it valid to address one element beyond the end of an array?

675


Why pointers are used in c?

592