07-25-2023, 11:42 AM
malloc() is used to allocate memory dynamically, and free() is used to release memory when it's no longer needed.
int *ptr = (int *)malloc(sizeof(int));
if (ptr != NULL) {
*ptr = 10;
printf("Value: %d\n", *ptr); // Output: 10
free(ptr); // Release memory
}
int *ptr = (int *)malloc(sizeof(int));
if (ptr != NULL) {
*ptr = 10;
printf("Value: %d\n", *ptr); // Output: 10
free(ptr); // Release memory
}
Also follow me on Youtube for videos about video games:
https://www.youtube.com/channel/UCxfkGVU...2mQ/videos
https://www.youtube.com/channel/UCxfkGVU...2mQ/videos