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

Answer Posted / lp

Declare a integer array size at runtime:
1.declare an interget pointer. - int *ptr
2.Get the size of array from user - int n
3.using malloc() ,allocate that many number of location to
the pointer. - ptr = malloc(n*sizeof(int));
4.Make use of the dynamically allocated array. - ptr[]

Is This Answer Correct ?    5 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How can I access an I o board directly?

612


What are local static variables? How can you use them?

635


Write a program to check armstrong number in c?

625


What is calloc malloc realloc in c?

579


Who developed c language and when?

569






What are directives in c?

535


How do we declare variables in c?

558


What do you mean by c what are the main characteristics of c language?

560


how is the examination pattern?

1585


Do you know what are the properties of union in c?

569


Explain what is the difference between #include and #include 'file' ?

571


Can stdout be forced to print somewhere other than the screen?

609


code for quick sort?

1604


Is a house a mass structure?

632


Can a function be forced to be inline? Also, give a comparison between inline function and the C macro?

646