Search This Blog

Friday, April 24, 2020

Dynamic memoey and static memory allocation in C Programming.

                          C-Programming

In this tutorial you will learn:-

1.  Dynamic memory allocation:- 


* Dynamic memory allocation means a program can obtain it's memory while it is running.
* Unwanted space at the run time pointer support dynamic memory allocation.
* There are 4 library functions in C Programming language known as memory management function .

malloc ( )  

malloc ( ) function is used to allocate blocks of memory in required size of bytes .

free ( )  

free ( ) function is used to release previously allocate memory space .

calloc ( ) 

 calloc function is used to allocate memory space for an array of element .

realloc ( ) 

 realloc ( ) function is used to modify the size of the previously allocate memory space .

Static memory allocation :-

The static memory is allocated during compilation time , when a variable is declared , based on their types , compiler allocate allocate space in memory , these variable can be indirectly accessed with the help of pointer variable , This way assigning the pointer variable is called static memory allocation .

let see one example to more clear this topic :-

// Write a program to find the sum of two number using pointer..

#include<stdio.h>
int main ( )
{
int a , b , c ;
int *a , * b ;
printf("enter value of a & b \n");
scanf("%d %d", &a , &b );
*a=&a;
*b=&b;
c = *a + *b ;
printf(" sum is is = %d\n", c);
return( 0 ) ;
}

OUTPUT

enter the value of a & b 10
20
sum of a and b is = 30

Mr. abhijeet dwivedi

Developer

Hey, I'm Abhijeet

0 comments:

Post a Comment

If you have any doubt, please let me know