Question #38977

Hello Sir,

how to create dynamic array using C language and how to search and print number using array in c.
please help me.
Thank You.
1

Expert's answer

2014-02-19T11:30:14-0500

Answer to question #38977 Programming, C++

To create dynamic array you should use malloc() function.

Function returns pointer at memory and accept size of array.

For example:


int *a = (int *)malloc(sizeof(int) * 10);


Allocate array a[10].

More information is available here:

http://www.cplusplus.com/reference/cstdlib/malloc/

To access to some variables use "[]". Like usual array.

For example:


int *a = (int *)malloc(sizeof(int) * 10);
int i;
for (i = 0; i < 10; i++) {
    a[i] = i;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!
LATEST TUTORIALS
APPROVED BY CLIENTS