Dear Stack Overflow Family - Happy Near Year !!! Have all a wonderful time.
I need help to learn memory management in C (and perhaps in general computing). Some book references would be great. All questions below are specific to C Programming.
Thanks in advance, Mehdi
No specific problems - just need advice.
Memories are allocated statically for this code char c[2] = { 'c', 'q'};
But,
char* c = malloc(sizeof(char)*2);
is allocated dynamically.
and here is how you iterate over string literals in C
char str[] = "example";
char *ptr = str;
while(*ptr != '\0') { // *ptr dereferences the pointer
printf("%c", *ptr);
ptr++;
}
Memory allocation: The compiler doesn't use a register to track free/used memory slots. Memory management is done at runtime. For dynamic allocation, functions like malloc() and free() are used to request and release memory. Static/local variables' memory is managed automatically - allocated when in scope and freed when out of scope.