Let us supposed the following code:
#include<stdlib.h>
void func1()
{
int a=2;
int b=3;
int c=4;
}
void func2()
{
int *ptr;
ptr = (int *)malloc(3 * sizeof(int));
}
int main()
{
func1();
printf("Point 1\n");
func2();
printf("Point 2\n");
}
My questions are:
- What does it happen with the memory allocated for the variables a, b
and c (that are local variables in "func1"), after the execution of
"func1" in the main function? The space required for storing these variables can be reused by other programs after this? - What does it happen with the memory allocated for "ptr" (that is local in "func2"), after the execution of "func2"? Should we free the memory before exiting the function?