Académique Documents
Professionnel Documents
Culture Documents
Syntax
#include <stdlib.h>
void *malloc (Size) void free (Pointer)
void *realloc (Pointer Size) void *calloc (NumberOfElements ElementSize )
Size
Specifies a number of bytes of memory.
Pointer
Points to the block of memory that was returned by the
NumberOfElements Specifies the number
of elements in the malloc or calloc subroutines. The Pointer parameter points
array. to the first (lowest) byte address of the block.
ElementSize Specifies the size of
each element in the
array.
malloc is dynamic memory allocation it allocates the memory and initialize garbage value.
calloc is similar to malloc but only difference is initialize zero
1. malloc takes only the size of the memory block to be allocated as input parameter.
2. malloc allocates memory as a single contiguous block.
3. if a single contiguous block cannot be allocated then malloc would fail.
1. calloc takes two parameters: the number of memory blocks and the size of each block of
memory
2. calloc allocates memory which may/may not be contiguous.
3. all the memory blocks are initialized to 0.
4. it follows from point 2 that calloc will not fail if memory can beallocated in non-contiguous
blocks when a single contiguous blockcannot be allocated.
malloc::::: Allocates memory requests size of bytes and returns a pointer to the Ist byte of
allocated space calloc:::::::: Allocates space for an array of elements initializes them to zero and
returns a pointer to the memory
Page 1 of « Fir
1 2> Last »
2 st
178
6
Is This Answer
Yes
Correct ? 227 No
Re: what is the main difference between c and c++?
110
6
Is This Answer
Yes
Correct ? 409 No
871
Is This Answer Yes
Correct ? 490 No
816
Is This Answer Yes
Correct ? 106 No
381
Is This Answer Yes
Correct ? 587 No
449
Is This Answer Yes
Correct ? 104 No
262
Is This Answer Yes
Correct ? 126 No
385
Is This Answer Yes
Correct ? 62 No
294
Is This Answer Yes
Correct ? 74 No
373
Is This Answer Yes
Correct ? 64 No
TOP DOWN
BOTTOM-UP
FOCUS ON PROCEDURES
FOCUS ON DATA
allocation is done
NEW OPERATOR
with malloc statement
584
Is This Answer Yes
Correct ? 86 No
* In C we are using
#include<stdio.h> as header file,
but
in C++ we are using
#include<iostream.h> as header
file.
322
Is This Answer Yes
Correct ? 45 No
166
Is This Answer Yes
Correct ? 58 No
121
Is This Answer Yes
Correct ? 44 No
242
Is This Answer Yes
Correct ? 46 No
165
Is This Answer Yes
Correct ? 30 No
139
Is This Answer Yes
Correct ? 39 No
266
Is This Answer Yes
Correct ? 35 No
173
Is This Answer Yes
Correct ? 73 No
Re: what is the main difference between c and c++?
140
Is This Answer Yes
Correct ? 24 No
132
Is This Answer Yes
Correct ? 27 No