Knowledge Walls
Hyderabad, Andhra Pradesh, India
Introduction [cont'd]
Input Output Functions [cont'd]
Structures and Unions [cont'd]
# Preprocessor [cont'd]
Calloc in Memory of Programming in C
Calloc is used to allocates space for an array of elements, initialize values as zero and returns the first address of allocated space to pointer variable.
(casttype *) calloc(no_of_records as int,size_of_datatype as int);
	struct product{
	   int product_no;
	   char product_name[20];
	void main(){
	   typedef struct product pro;
	   pro *product_ptr;
	   int i;
	   //Allocates the memory for structure variable using calloc
	   product_ptr = (pro *) calloc(5,sizeof(pro));
	   for (i=0;i<5;i++){
	       printf("Enter the product no : ");
	       printf("Enter the product name : ");
	   for (i=0;i<5;i++){
	       printf("%d : %s\n",(product_ptr+i)->product_no,(product_ptr+i)->product_name);
Enter the product no : 101
Enter the product name : Hamam
Enter the product no : 102
Enter the product name : Liril
Enter the product no : 103
Enter the product name : Himalaya
Enter the product no : 104
Enter the product name : Colgate
Enter the product no : 105
Enter the product name : Lux

101 : Hamam
102 : Liril
103 : Himalaya
104 : Colgate
105 : Lux
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
keep your tutorials and learnings with KnowledgeWalls. Don't lose your learnings hereafter. Save and revise it whenever required.
Click here for more details