what is mallloc()?how it works?

Answers were Sorted based on User's Feedback



what is mallloc()?how it works?..

Answer / 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

what is mallloc()?how it works?..

Answer / ravi chandra

malloc function is used to allocate some space in memory for
the current program that we are running.
malloc() function actually return s the value of the address
of the memory in the memory segment
c=malloc();
it gives the address to the variable c.


h=malloc(sizeof(struct node));
it returns the address of structure for the variable h;
some h=1000; (address value)

Is This Answer Correct ?    1 Yes 1 No

what is mallloc()?how it works?..

Answer / raghavan

Every process has a address boundary. When a process does a malloc, memory is allocated from this boundary location and the process address boundary is moved to the new end. In linux, there is a function sbrk() that allows to change the process address boundary. sbrk(0) will return the current process address boundary and sbrk(n) will move the process boundary by n bytes.
malloc internally uses this feature to allocate memory for the requesting process.

Is This Answer Correct ?    0 Yes 0 No

what is mallloc()?how it works?..

Answer / srinath, hyd

ya. this is an memory allocation porpose.
some other allocations are there calloc(), alloc()

Is This Answer Correct ?    0 Yes 1 No

Post New Answer

More C Interview Questions

main() { int a=5; printf(?%d,%d,%d\n?,a,a< <2,a>>2); } Answer: 5,20,1 please explain this code in detail

6 Answers   TCS,


we called a function and passed something do it we have always passed the "values" of variables to the called function. such functions calles are called a) calls by reference b) calls by value c) calls by zero d) none of the above

0 Answers  


What is the output for the program given below typedef enum grade{GOOD,BAD,WORST,}BAD; main() { BAD g1; g1=1; printf("%d",g1); }

4 Answers   ADITI,


What is the difference between strcpy() and memcpy() function in c programming?

0 Answers  


Is malloc memset faster than calloc?

0 Answers  






Describe static function with its usage?

0 Answers  


Which are low level languages?

0 Answers  


main() { unsigned int k = 987 , i = 0; char trans[10]; do { trans[i++] =(char) (k%16 > 9 ? k%16 - 10 + 'a' : '\0' ); } while(k /= 16); printf("%s\n", trans); }

4 Answers   Vector,


Is null a keyword in c?

0 Answers  


What is a pragma?

0 Answers  


How we can set and clear bit in a byte using macro function?

2 Answers   L&T, Samsung,


What is register variable in c language?

0 Answers  


Categories