Ask your own question, for FREE!
Computer Science 22 Online
OpenStudy (anonymous):

Is there anyway in C we could create an array dynamically??? Like when the user gives the input as 5, then we need to have an array of length 5 ...???? any suggestion mates???

OpenStudy (anonymous):

malloc

OpenStudy (anonymous):

if we could Use malloc, then we would loose the contiguous memory allocation of the array????? wont we?

OpenStudy (anonymous):

wrong, malloc gives you a contiguous block of memory of the specified size

OpenStudy (anonymous):

can U pls help with the coding part???

OpenStudy (anonymous):

Example: Allocate a character buffer of 512 characters. char* Buffer = malloc ( 512 );

OpenStudy (anonymous):

Sorry forgot the cast. char* Buffer = (char*) malloc ( 512 );

OpenStudy (anonymous):

cool :) :) :) got it :) thanks a lot :)

OpenStudy (anonymous):

malloc

OpenStudy (anonymous):

Also don't forget to free() it after using malloc() ;)

OpenStudy (anonymous):

sure sure :) :)

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!