what is mallloc()?how it works?
Answers were Sorted based on User's Feedback
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 |
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 |
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 |
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 |
Q.11 Generate the following pattern using code in any language(c/c++/java) for n no. of rows 1 1 1 1 2 1 1 3 3 1 1 4 6 4 1
Print the foll in C...eg when n=5 the o/p must b + + + + + + + + + + + + + + + + +
how to implement stack operation using singly linked list
Explain demand paging.
What are the salient features of c languages?
What is realloc in c?
What does a function declared as pascal do differently?
could u able to tell about suresoft technical session
what is C?
Write a C program to convert an integer into a binary string?
#include<stdio.h> int f(int,int); int main() { printf("%d",f(20,1)); return 0; } int f(int n,int k) { if(n==0) return 0; else if(n%2)return f(n/2,2*k)+k; else return f(n/2,2*k)-k; } how this program is working and generating output as 9....?
Can include files be nested? How many levels deep can include files be nested?