0% found this document useful (0 votes)
6 views1 page

Dynamic Memory Allocation in C

Uploaded by

ridashaikh215
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
6 views1 page

Dynamic Memory Allocation in C

Uploaded by

ridashaikh215
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 1

Dynamic Memory Allocation in C

The functions malloc() and calloc() are library functions that allocate memory
dynamically. Dynamic means the memory is allocated during runtime (execution of
the program) from the heap segment.
malloc() allocates a memory block of given size (in bytes) and returns a
pointer to the beginning of the block. malloc() doesn’t initialize the allocated
memory. It doesn't initialize memory at execution time, so it has garbage value initially. It
returns NULL if memory is not sufficient.

calloc() allocates the memory and also initializes every byte in the allocated
memory to 0. It initially initialize all bytes to zero. It returns NULL if memory is not
sufficient.

No. malloc() calloc()

1. malloc() function creates a single block of memory calloc() function assigns multiple blocks of memory to
of a specific size. a single variable.

2. The number of arguments in malloc() is 1. The number of arguments in calloc() is 2.

3. malloc() is faster. calloc() is slower.

4. malloc() has high time efficiency. calloc() has low time efficiency.

5. The memory block allocated by malloc() has a The memory block allocated by calloc() is initialized by
garbage value. zero.

6. malloc() indicates memory allocation. calloc() indicates contiguous allocation.

Math Functions :
Square Root
To find the square root of a number, use the sqrt() function:
Example : printf("%f", sqrt(16));
Round a Number
The ceil() function rounds a number upwards to its nearest integer, and the floor() method
rounds a number downwards to its nearest integer, and returns the result:
Example printf("%f", ceil(1.4)); return 2
printf("%f", floor(1.4)); return 1
Power
The pow() function returns the value of x to the power of y (xy):
Example : printf("%f", pow(4, 3));

You might also like