From the course: Master C Language Pointers
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Exploring allocation functions - C Tutorial
From the course: Master C Language Pointers
Exploring allocation functions
- Here are four memory allocation functions from the standard C library, each of which deals with memory allocation and pointers, malloc(), calloc(), realloc() and free(). The malloc() function allocates uninitialized storage just like any variable or array in C. The calloc() function on the other hand, allocates and initializes memory, for numeric storage values are set to zero for character storage, values are set to the NULL character. The realloc() function dynamically resizes an existing buffer, for example, making it larger. The contents of the old buffer are copied to the new buffer as much as possible, and yes it's possible to resize an existing buffer by specifying it's pointer as both the function's first argument and as the return value. As with the malloc() function, the realloc() function doesn't initialize the added storage. The free() function is used on an allocated buffer to recover the memory and allow…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
Comparing arrays and pointers3m 36s
-
(Locked)
Allocating storage3m 29s
-
(Locked)
Exploring allocation functions4m 58s
-
(Locked)
Accessing the buffer3m 41s
-
(Locked)
Working with pointers in structures2m 18s
-
(Locked)
Creating structure pointers3m 29s
-
(Locked)
Saving pointers and buffers4m 31s
-
(Locked)
Challenge: Saving and reading a record1m 6s
-
(Locked)
Solution: Saving and reading a record2m 15s
-
-
-