Where in memory are my variables stored in C?

发布时间:2024年01月19日
global variables -------> data 
static variables -------> data 

constant data types -----> code and/or data. 
	Consider string literals for a situation when a constant itself would be stored in the data segment, 
		and references to it would be embedded in the code
		
local variables(declared and defined in functions) --------> stack 
variables declared and defined in main function -----> also stack 
pointers(ex: char *arr, int *arr) -------> data or stack, 
	depending on the context. 
	C lets you declare a global or a static pointer, 
		in which case the pointer itself would end up in the data segment.
		
dynamically allocated space(using malloc, calloc, realloc) --------> heap
It is worth mentioning that "stack" is officially called 
	"automatic storage class".
文章来源:https://blog.csdn.net/qq_38963393/article/details/135698287
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。