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 do you redirect a standard stream?

871


What are the two types of functions in c?

786


Explain Basic concepts of C language?

843


Is c high or low level?

796


What is time complexity c?

765


What is the difference between char array and char pointer?

781


How can you find the exact size of a data type in c?

792


What is the difference between fread buffer() and fwrite buffer()?

919


What are the basic data types associated with c?

1053


What does c mean in standard form?

878


A global variable when referred to in another file is declared as this a) local variable b) external variable c) constant d) pointers

892


How can you invoke another program from within a C program?

833


Explain goto?

933


What is s or c?

809


How are Structure passing and returning implemented by the complier?

940