Hi,
Can anyone tell when is memory allocated to variables like Automatic, Global, Static etc. ?? I think it is during compile time but exactly how I don't know.
This is a topic on Memory Allocation for variables in C within the Programmers Corner forums, part of the Technology category; Hi, Can anyone tell when is memory allocated to variables like Automatic, Global, Static etc. ?? I think it is ...
Hi,
Can anyone tell when is memory allocated to variables like Automatic, Global, Static etc. ?? I think it is during compile time but exactly how I don't know.
No,no memory gets allocated during compile time,a simple compilation only validates your program for syntactical and semantical errors,parses the code and makes it ready for the linker;not to complicate matters further but i think you might be confused with .bss and .data which are part of the data segment in the heap and are generated during compile time.
Memory is only allocated once your run the program,every program has its own stack and heap trace,all static,global variables are stored in the program stack while block scope variables are allocated memory in the heap.
As for auto,im not really sure about the way c handles it but in c++ all block level variables are defined as auto by default meaning they are deallocated once their scope runs out.As for register variables,they are stored in the cpu register although its only a direction and not a compulsion ie they may or may not.