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 is chain pointer in c?

605


why return type of main is not necessary in linux

1710


write a c programming using command line argument,demonstrate set operation(eg;union,intersection,difference) example output is c:>setop 12 34 45 1 union 34 42 66 c:>setop 12 34 1 42 66 c:>setop 12 34 diff 12 56 67 78 setop 12 34

1633


Suppose we have a table name EMP as below. We want to perform a operation in which, I want to change name ‘SMITH’ from as ‘SMITH JAIN’. Also I want to change the name of the column from ENAME to E_NAME. EMPNO ENAME JOB MGR HIREDATE SAL 7369 SMITH Coder 7902 17-DEC-80 800 7499 ALLEN SALESMAN 7698 20-FEB-81 1600 7521 WARD SALESMAN 7698 22-FEB-81 1250

1513


What is meant by int main ()?

723






What is file in c language?

581


Explain how can I write functions that take a variable number of arguments?

619


Why do we need a structure?

595


What is difference between %d and %i in c?

698


List some of the static data structures in C?

766


a linearly ordered set of data elements that have the same structure and whose order is preserved in storage by using sequential allocation a) circular b) ordinary c) array d) linear list

639


What is FIFO?

678


How can I do peek and poke in c?

623


What is c standard library?

694


How can a number be converted to a string?

611