Transcript for:
Understanding Malloc in C Language

in the c-stand library the most powerful function is malloc now malloc is fairly simple in what it does it allocates Heap memory as requested in more detail malloc will take a number of bytes you want as a number allocate those bytes on the Heap and return a pointer to those bytes since Malik doesn't know the type of the pointer you may need to cast it if you're using a more strict language such as C plus often you want to use size up with malloc for example if we want to allocate three ends but we don't know what the compiler will set as the size of an integer we can use size of and times 3 to allocate enough bytes to fit three ends for example our code will look something like this here we multiply the size of an N by 3. this makes our code more portable across compilers only if you ever want to try to allocate more memory than you have available malloc will return null and keep in mind when you're done using the memory it's good practice to both free and assign your pointer to null after you're finished with your memory if you want to see more videos like this check out the playlist on your screen right now and I will see you later