Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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

What are actual arguments?

1052


What's the best way of making my program efficient?

1046


What is difference between Structure and Unions?

1195


What is the difference between arrays and pointers?

1076


Add Two Numbers Without Using the Addition Operator

778


Multiply an Integer Number by 2 Without Using Multiplication Operator

728


What is #include stdio h and #include conio h?

1051


Can you subtract pointers from each other? Why would you?

921


Which header file is essential for using strcmp function?

1430


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

1054


How can I call a function with an argument list built up at run time?

1179


What is atoi and atof in c?

1040


application areas a 'c' a) operating system b) graphics, interpreter, assembler c) program evalution, communication softwares d) all the above

1021


Explain how can I open a file so that other programs can update it at the same time?

1064


Is array a primitive data type in c?

1008