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

Write a program to use switch statement.

0 Answers   Agilent, Integreon, ZS Associates,


which do you prefer C or Pascal?

1 Answers  


Explain what will the preprocessor do for a program?

0 Answers  


Write a program that will read the input of any number of digits n in a row of shafh showing the breakdown of the printing and printing figures by the recursive function.

0 Answers  


What is c basic?

0 Answers  






typedef struct { int i:8; char c:9; float f:20; }st_temp; int getdata(st_temp *stptr) { stptr->i = 99; return stptr->i; } main() { st_temp local; int i; local.c = 'v'; local.i = 9; local.f = 23.65; printf(" %d %c %f",local.i,local.c,local.f); i = getdata(&local); printf("\n %d",i); getch(); } why there there is an error during compiling the above program?

1 Answers  


What do you mean by recursion in c?

0 Answers  


how to implement stack operation using singly linked list

2 Answers  


How would you rename a function in C?

0 Answers   Tech Mahindra,


what is the use of using linked list and array?

10 Answers   Infosys, TCS,


What are types of functions?

0 Answers  


Write a c pgm for leap year

11 Answers   College School Exams Tests, IBM, TCS,


Categories