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 are the string functions? List some string functions available in c.

594


What is printf () in c?

574


What are pointers? What are stacks and queues?

571


what is associativity explain what is the precidence for * and & , * and ++ how the folloing declaration work 1) *&p; 2) *p++;

1998


What is fflush() function?

631






What is declaration and definition in c?

517


find the output? void r(int a[],int c, int n) { if(c>n) { a[c]=a[c]+c; r(a,++c,n); r(a,++c,n); } } int main() { int i,a[5]={0}; r(a,0,5); for(i=0;i<5;i++) printf("\n %d",a[i]); getch(); }

1855


What is a volatile keyword in c?

631


How can a program be made to print the line number where an error occurs?

638


Write a C program in Fibonacci series.

622


Explain what is wrong with this statement? Myname = ?robin?;

986


how we can make 3d venturing graphics on outer interface

3989


Compare and contrast compilers from interpreters.

673


What are the complete rules for header file searching?

662


while loop contains parts a) initialisation, evalution of an expression,increment /decrement b) initialisation, increment/decrement c) condition evalution d) none of the above

726