I have my following ansi C code example:
void Example1()
{
int i;
int *arr = (int*)malloc(5*sizeof(int));
for (i=0;i<5;i++)
arr[i]=i;
}
void Example2()
{
int j;
j=0;
}
void main()
{
Example1();
Example2();
}
when the program run, the "Example1" function is called first and then followed the "Example2" function.
Assumaply, when the compiled program in the "Example1", "i" variable is allocated to the
0x00000000 memory address and "arr" is allocated to the
0x00000004 memory address.
After passing through to the end of line in "Example1" and go to the "Example2" and starting process to allocated to the "j" variable. Now, stop it. I have some following questions and really need you guys to help me out.
Where exactly address location of "j" variable is?
Is the "Example1" after completing its mission in main program automatically free the memory of "i" and "arr" variable?
Every specific compiler have a mechanism automatically free the memory after using or not? (or depend on something?)
Thanks guys in advance