By considering that the memory is divided into four segments: data, heap, stack, and code, where do global variables, static variables, constant data types, local variables (defined and declared in functions), variables (in main function), pointers, and dynamically allocated space (using malloc and calloc) get stored in memory?
I think they would be allocated as follows:
- Global variables -------> data
- Static variables -------> data
- Constant data types -----> code
- Local variables (declared and defined in functions) --------> stack
- Variables declared and defined in main function -----> heap
- Pointers (for example,
char *arr
, int *arr
) -------> heap
- Dynamically allocated space (using malloc and calloc) --------> stack
I am referring to these variables only from the C perspective.
Please correct me if I am wrong as I am new to C.
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…