The free function in C is used to deallocate memory that was previously allocated by malloc, calloc, or realloc. It takes as an argument a pointer to the memory that needs to be freed. Once the memory has been freed, the pointer should not be used again as it may cause undefined behavior
Syntax :
free ( ) ;
Example :
free ( ptr ) ;
//free function #include<stdio.h> #include<stdlib.h> int * getting_values() { int i; int *ptr=(int *)malloc(3*sizeof(int)); for(i=0; i<3; i++) { printf("Enter a integer : "); //10,20,30 scanf("%d",ptr+i); } return ptr; } int main() { int i,n=0; int *ptr=getting_values(); for(i=0; i<3; i++) { n+=*(ptr+i); //n=n+10 => +20 =>+30 } printf("Total : %d ",n); free(ptr); ptr=NULL; return 0; }To download raw file Click Here
Enter a integer : 11 Enter a integer : 12 Enter a integer : 13 Total : 36
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions