When are variables in main() allocated? Especially how much memory is allocated for the pointer to arrays arr and 2d in the following:
int main()
{
float a, b;
int *b;
float *(arr)[6];
float *(2d)[5][5];
}
Are these considered auto, global, or static?
Memory for all the local variables declared inside a function will be allocated during run time, before executing a function. For each function an activation record will be created in the stack of the process memory, which will contains all the local variables. Once the function execution is completed activation record will be poped out.
All the variables declared inside a function are consider as
autoonly, unless it is explicitly declared asstaticorregister. Variables declared outside a function will be considered as global.If a variable is declared inside or outside a function as static, means memory allocation will be done at compile time itself, which will be in data segment(or bss).
All the pointer variable is going to store some virtual address(of variable of any type or function). So size of a pointer variable is 4 bytes in case of 32 bit machine and 8 bytes in case of 64 bit machine.