Table of Contents
This guide covers calloc ()() function in c with practical context and easy-to-follow details. Use it to understand the subject and apply the information confidently.
Declaring the Function Calloc ()() in C
Here is the declaration for calloc () in C:
void * calloc ( so - phan - tu , kich - co - phan - tu )
Parameters
So-phan-tu : This is the number of elements to be allocated.
Kich-co-phan-tu : This is the size of the element.
Returns the Value
This function returns a pointer to the allocated memory, or returns NULL if the request fails.
For Example
The following C program illustrates the usage of calloc () in C:
#include #include int main () { int i , n ; int * a ; printf ( "Nhap so phan tu: n" ); scanf ( "%d" ,& n ); a = ( int *) calloc ( n , sizeof ( int )); printf ( "Nhap %d so: n" , n ); for ( i = 0 ; i < n ; i ++ ) { scanf ( "%d" ,& a [ i ]); } printf ( "Cac so vua nhap la: n" ); for ( i = 0 ; i < n ; i ++ ) { printf ( "%d " , a [ i ]); } return ( 0 ); } Compiling and running the above C program will result:
According to Tutorialspoint
Previous lesson: Function strtoul () in C
Next lesson: Free () function in C
Frequently Asked Questions
What should I check before following these steps?
Confirm device and software compatibility, save important data, and make sure you have the required permissions, files, and account access.
Why might the process not work?
Common causes include outdated software, missing permissions, incompatible hardware, an unstable connection, or completing a step in the wrong order.
Can I undo the changes if necessary?
That depends on the tool or setting. Use built-in restore options when available, keep a backup, and record the original configuration first.
Was this article helpful?
Your feedback helps us improve.
Reader Comments 0
Sign in with email or Google to join the discussion.