I have a question to ask, which occurred when reading the concept of static variables. If I create an allocated block of memory in a function, using malloc, and then the function returns to main, without having used free() on the allocated memory, will that memory block be susceptible to changes in the course of the program, or not? I mean, after I leave the function is it possible that the memory block can be overwritten by another process, while I wanted to use it and/or edit it in my way, or is it “locked” from something like that, until I free it? Is it possible for the block to be considered as free of data before I free it?
I have a question to ask, which occurred when reading the concept of static
Share
Once you
malloced a certain num ber of bytes, it’s going to be alive throughout your program’s lifetime unless you explicitlyfreeit.It doesn’t matter in which function you did the
malloc, the memory is going to be alive for you to use anywhere in your program provided you have a valid pointer to themalloced memory.