Table of Contents
This guide covers malloc ()() function in c with practical context and easy-to-follow details. Use it to understand the subject and apply the information confidently.
Declare Malloc ()() in C
Below is the declaration for malloc () in C:
void * malloc ( kich - co )
Parameters
Kich-co : This is the size of the memory block (in bytes).
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 malloc () in C:
#include #include #include int main () { char * str ; /* lan cap phat bo nho ban bau */ str = ( char *) malloc ( 15 ); strcpy ( str , "QTMTeam" ); printf ( "Chuoi = %s, tai Dia chi = %un" , str , str ); /* tai cap phat lai bo nho */ str = ( char *) realloc ( str , 25 ); strcat ( str , ".@gmail.com" ); printf ( "Chuoi = %s, tai Dia chi = %un" , str , str ); free ( str ); return ( 0 ); }
Compile and run the above C program to see the results.
According to Tutorialspoint
Previous lesson: Free () function in C
Next lesson: Function realloc () in C
FAQ
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.
Reader Comments 0
Sign in with email or Google to join the discussion.