what is mallloc()?how it works?

Answer Posted / vignesh1988i

malloc is briefly termed as Memory ALLOCation ......
whenever we write a program in C we will declare some
variables or arrays for a size more than whatever we need ,
etc etc..... so some variables are getting used correctly
and in arrays only some of the memory spaces are getting
used because the user dont know how much spaces he is gonna
use.......so here some memory is getting wasted without
using it.... so there comes a concept called DYNAMIC MEMORY
ALLOCATION in C...

we will give the values for how much memory we need at the
run time of the program... but this concept also only 85%
efficient... this has three types :
1)malloc();
2)calloc();
3)realloc();
malloc() is a function present in ALLOC.H standard library
which is used to allocate memory at run time (ie) in single
or in blocks.....

the syntax is :
pointer_variable=(typecasting
datatype*)malloc(sizeof(datatype));

this pointer variable should be of same datatype as the
typecasting datatype........

thank u

Is This Answer Correct ?    4 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain how do you sort filenames in a directory?

785


simple program of graphics and their output display

1677


What is this infamous null pointer, anyway?

780


Write a program to replace n bits from the position p of the bit representation of an inputted character x with the one's complement. Method invertBit takes 3 parameters x as input character, p as position and n as the number of positions from p. Replace n bits from pth position in 8 bit character x. Then return the characters by inverting the bits.

3914


How can you avoid including a header more than once?

723






What do header files do?

797


Why are algorithms important in c program?

809


What is a node in c?

720


What is the difference between declaring a variable and defining a variable?

923


which of the following is allowed in a "C" arithematic instruction a) [] b) {} c) () d) none of the above

1369


What is pointer in c?

934


GIven a sequence of characters. How will you convert the lower case characters to upper case characters. ( Try using bit vector - sol given in the C lib -> typec.h)

847


how much salary u want ? why u join in our company? your domain is core sector why u prefer software ?

1705


What are qualifiers?

785


How can this be legal c?

822