Knowledge Walls
Venkatesan
Hyderabad, Andhra Pradesh, India
Passcode:
Introduction [cont'd]
Input Output Functions [cont'd]
Structures and Unions [cont'd]
# Preprocessor [cont'd]
Free in Memory of Programming in C
2208 Views
Free 
Free is used to free already allocated memory space.
Syntax 
free(pointer_variable);
Program
	#include
	void main(){
	   int *ptr;
	   int i;
	   //Allocates memory for pointer variable 5 * 2 (10) bytes
	   ptr = (int *) malloc(5 * sizeof(int));
	   for (i=0;i<5;i++){
	       printf("Enter a number : ");
	       scanf("%d",(ptr+i));
	   }
	    for (i=0;i<5;i++){
	       printf("\t%d",*(ptr+i));
	   }
	   //Free the pointer variable memory
	   free(ptr);
	}
Output 
Enter a number
45
Enter a number
23
Enter a number
67
Enter a number
98
Enter a number
45

45 23 67 98 45
Previous Topics
Previous lessons of current book.
Best Lessons of "Programming in C"
Top lessons which are viewed more times.
Structures and Unions of Programming in C
Input Output Functions of Programming in C
Structures and Unions of Programming in C
  Copyright © 2014 Knowledge walls, All rights reserved
KnowledgeWalls
keep your tutorials and learnings with KnowledgeWalls. Don't lose your learnings hereafter. Save and revise it whenever required.
Click here for more details