Knowledge Walls
Venkatesan
Hyderabad, Andhra Pradesh, India
Passcode:
Introduction [cont'd]
Input Output Functions [cont'd]
Structures and Unions [cont'd]
# Preprocessor [cont'd]
Realloc in Memory of Programming in C
1939 Views
Realloc 
Realloc is used to re-allocate memory which is already allocated memory.
Syntax 
(casttype *) realloc(pointer variable,size_of_bytes as int);
Program
	#include
	void main(){
	   int *ptr;
	   int i;
	   //Allocates memory for pointer variable 5 * 2 (10) bytes
	   ptr = (int *) malloc(2 * sizeof(int));
	   //Reallocates memory again for pointer variable using realloc
	   ptr = realloc(ptr,5 * sizeof(int));
	   for (i=0;i<5;i++){
	       printf("Enter a number : ");
	       scanf("%d",(ptr+i));
	   }
	   for (i=0;i<5;i++){
	       printf("%d\t",*(ptr+i));
	   }
	}
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
Next Topics
Next 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