This project focuses on dynamic memory allocation in C using malloc and free. It covers how to allocate memory dynamically, how to manage memory, and how to avoid memory leaks. The project aims to provide a deep understanding of these fundamental concepts in C programming.
- Dynamic Memory Allocation in C
- Understanding and Using
mallocandfreein C - Memory Management in C
- Avoiding Memory Leaks in C
- What is dynamic memory allocation and why is it needed.
- How to use
malloc,calloc,realloc, andfreeto manage memory. - How to handle memory allocation errors.
- How to avoid memory leaks and dangling pointers.
| Task Name | File | Description |
|---|---|---|
| Create an array of chars | 0-create_array.c | Creates an array of chars and initializes it with a specific char. |
| Duplicate a string | 1-strdup.c | Returns a pointer to a newly allocated space in memory, which contains a copy of the string given as a parameter. |
| Concatenate two strings | 2-str_concat.c | Concatenates two strings. |
| Allocate a grid | 3-alloc_grid.c | Returns a pointer to a 2 dimensional array of integers. |
| Free a grid | 4-free_grid.c | Frees a 2 dimensional grid previously created by your alloc_grid function. |
| Concatenate all arguments | 100-argstostr.c | Concatenates all the arguments of your program. |
| Split a string into words | 101-strtow.c | Splits a string into words. |
To compile any of the C files, use the following command:
gcc -Wall -Werror -Wextra -pedantic <filename.c> -o <outputfile>For example, to compile 0-create_array.c:
gcc -Wall -Werror -Wextra -pedantic 0-create_array.c -o create_arrayTo run the compiled program:
./create_array