In C programming, the calloc() function is used to dynamically allocate memory for an array during runtime, similar to the malloc() function. However, unlike malloc(), calloc() initializes the memory block to all zero bits. The function is defined in the stdlib.h library.
The calloc() function takes two arguments, the number of elements in the array and the size of each element. It then returns a pointer to the first byte of the allocated memory block.
Here is an example of how the calloc() function can be used in C:
Syntax :
void* calloc ( size_t n , size_t size )
Example :
int *ptr = int , calloc ( 5 , size ( int ) )
//calloc in Pointers #include<stdio.h> #include<stdlib.h> int main() { //void* calloc(size_t n,size_t size) int i,n; printf("\nEnter The Limit : "); scanf("%d",&n); int *ptr=(int *)calloc(n,sizeof(int)); if(ptr==NULL) { printf("Memory Not Available ..."); exit(1); } for(i=0; i<n; i++) { printf("Enter a integer : "); scanf("%d",ptr+i); } for(i=0; i<n; i++) { printf("\n%d : %d ",&ptr+i,*(ptr+i)); } return 0; }To download raw file Click Here
Enter The Limit : 5 Enter a integer : 1 Enter a integer : 2 Enter a integer : 3 Enter a integer : 4 Enter a integer : 5 6356724 : 1 6356728 : 2 6356732 : 3 6356736 : 4 6356740 : 5
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions