Skip to main content
Brave Programmer Logo

BraveProgrammer

BraveProgrammer

HomeProjectsBlogsCoursesLessonsAbout

Site footer

BraveProgrammer

Free coding courses, practical tutorials, and real projects from BraveProgrammer. Learn web development with React, Next.js, and TypeScript.

Navigation

  • Home
  • Projects
  • Blogs
  • Courses

Resources

  • About
  • Lessons

© 2026 BraveProgrammer. All rights reserved.

  1. Courses
  2. /
  3. C Programming Fundamentals

Lesson 17 of 50 · c

Dynamic Memory – malloc & free

Duration: 12 mins

The heap provides memory at runtime via <stdlib.h> functions:

  • void *malloc(size_t size) – allocate uninitialized memory.
  • void *calloc(size_t count, size_t size) – allocate zero‑initialized memory.
  • void *realloc(void *ptr, size_t newSize) – resize an existing block.
  • void free(void *ptr) – return memory to the system.

Always check the pointer returned by malloc/calloc for NULL. Forgetting free causes memory leaks; double‑free leads to undefined behavior.

Previous: Strings – Character ArraysNext: Structures (`struct`)