Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Dynamic memory allocation in C (malloc, free)
#1
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
}
Also follow me on Youtube for videos about video games:
https://www.youtube.com/channel/UCxfkGVU...2mQ/videos
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Understanding pointers and memory addresses in C Qomplainerz 0 248 07-25-2023, 11:41 AM
Last Post: Qomplainerz

Forum Jump:


Users browsing this thread: 6 Guest(s)