Knowledge Walls
Venkatesan
Hyderabad, Andhra Pradesh, India
Passcode:
Introduction [cont'd]
Input Output Functions [cont'd]
Structures and Unions [cont'd]
# Preprocessor [cont'd]
Malloc in Memory of Programming in C
2536 Views
Malloc 
Malloc is used to allocates specified size of bytes memory space and returns the first address of allocated space to pointer variable.
Syntax 
(casttype *) malloc(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(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));
	   }
	}
Output 
Enter a number
23
Enter a number
34
Enter a number
45
Enter a number
46
Enter a number
87

23 34 45 46 87
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