This article is very important for the person who wants to understand c language. Anyone who is going for any interview for a good software company must read the following article as the questions asked in the tests and interviews need the candidate to be clear in the following concepts. This article would ensure that the answers to the following questions are answered properly:
How are variables and pointers actually represented at the machine level?
What is the reason behind the dangling pointers?
Why do the dereference error occurs?
Why do we have other bugs on pointers?
Hence I recommend every person who wants to have a good understanding to read this article. I have explained concepts by transforming them into the form of questions. The article has been written in such a way that it becomes very simple for the user to understand this.
In C language we have different types of variables like global variable, local variable, parameter to the function and dynamically allocated variable.
But do we know how memory is allocated to these variables and where are these variables stored?
This concept is very important to understand. So let’s discuss this and understand the language better which would help us in dealing with many errors in the program.
We consider 3 kinds of memory in a computer system
FIXED MEMORY:
This memory is used to store the program written or the application being run (i.e. the executable code) and the constant variables or other constant structures. The global and the static variables are also stored in the fixed memory. This memory is categorized into code memory, data memory etc. The code memory stores the executable code while the data memory stores the global and the static variables.
STACK MEMORY:
The stack memory is a data structures which follows the policy of Last In First Out (LIFO).The stack memory is used to store the static data which includes the variables which are declared at the start of the program like the fixed arrays, local variables and the parameters which are passed to a function during the function call. Other than this the return address pointer, frame pointer (the pointer which is used to point to the starting of the frame just below) and other registers. The life of the static variables ends as soon as the function returns or the program execution stops. The stack memory is used separately for separate programs in an operation system. The memory in stack is allocated at the compile time.
Disadvantage: The memory declared first remains the same i.e. if we declare large memory then there is wastage of memory while if we declare lesser memory then we are in a problem.
Advantage: The memory allocated is deallocated automatically after the function returns and hence the same memory is available for re-use again.
HEAP MEMORY
The heap memory is used to allocate space to the dynamic data. The data whose size can shrink and expand as the requirements vary. We can allocate the extra memory whenever required using command such as malloc(), calloc(), realloc() and de-allocate the space already allocated using command such as free(), delete(). The memory in heap is allocated at the run time.
Wecan take HEAP memory as a group of nodes (circles) and every node is reachable only if It has a direct or indirect reference from some root node (pointer) which is stored in STACK memory. When we use memory allocation functions like malloc, calloc or realloc the memory node are selected and linked to the specified root node. Now if we don’t free the nodes of HEAP memory before the root node is de-allocated, the reference to those memory nodes is lost and they become unreachable, hence known as garbage memory or memory leak. Hence to avoid this problem the programmer must free the memory after it’s use.
Advantage: This memory can be anytime shrunk or expanded when ever the requirements of the program changes.
Disadvantage: We have to manually deallocate the memory allocatd using function like free or delete, otherwise the memory which is not deallocated at the proper time goes to the garbage and is not available for re-use.
We can represent the above memories in a diagram as

Example
Consider the program
int x=4;
main()
{
int z;
char* y;
y= malloc(6);
y = "Hello";
printf(“%c”, *y);
z = square(x);
printf(“%d”, z);
free(y);
}
int square(Int k)
{
return k*k;
}
Now we see which variables in the program are stored where.
In this program we have different types of variables like x as global variable, z & k as local variable and as parameter to the function and y is dynamically allocated variable. So x is stored in fixed memory, z & k are stored in Stack Memory and the pointer y is also stored in stack memory while the 6 bytes (allocated by malloc) which are pointees of pointer y are stored in heap memory.
Some private photo files you delete on your phone, even if they are permanently deleted, may be retrieved by others.
Your article helped me a lot, is there any more related content? Thanks!
Thank you for your sharing. I am worried that I lack creative ideas. It is your article that makes me full of hope. Thank you. But, I have a question, can you help me?
情感是人类复杂而深刻的内心体验,它贯穿于我们的思维、行为和关系中,既是生命的动力,也是成长的镜子。以下是从心理学、社会学和哲学角度对情感的剖析,以及如何在现代社会中更好地理解和经营情感:
一、情感的本质与功能
生物本能与社会建构的双重性
生物学视角:情感根植于进化需求(如恐惧驱使逃生、爱促进繁衍)。杏仁核作为“情绪警报器”,能在5毫秒内触发本能反应。
社会学视角:文化背景塑造情感表达方式(如东亚的含蓄内敛 vs 西方的直接热情),甚至定义“正常”与“异常”。
认知的催化剂
情感影响决策质量:研究显示,愤怒状态下的人更容易做出高风险选择,而积极情绪能提升创造力(如“心流”状态)。
二、情感的四大维度(根据Plutchik情绪轮盘)
维度 典型情感 过度状态 匮乏状态
活力 喜悦、兴奋 亢奋、躁狂 抑郁、麻木
紧张 焦虑、警觉 恐惧、惊慌 冷漠、疏离
接受 安宁、满足 迷茫、厌倦 空虚、绝望
冲突 愤怒、厌恶 攻击性、偏执 顺从、压抑
三、现代社会的三大情感困境
数字化情感疏离
即时通讯工具(如微信)缩短了物理距离,却拉长了心理距离。表情包代替真实表情,点赞量取代深度共鸣,“孤独流行病”成为全球性现象。
情绪价值供需失衡
在职场、家庭中,“情绪劳动”(如客服安抚客户)常被剥削,而个人情感需求未被满足。社交媒体上“完美人设”加剧自我否定。
情感表达的范式危机
“爱意”被量化(如情人节玫瑰数量)、焦虑被娱乐化(如短视频宣泄),导致情感体验浅表化。
四、提升情感智慧的实践策略
**1. 情绪觉察:建立“情感日志”**
记录每日情绪波动事件,标注触发点与身体反应(如胃部紧绷、手心出汗)。通过观察发现重复模式(如“会议发言恐惧源于童年批评经历”)。
2. 非暴力沟通(NVC)四步法
观察:“本周我三次因工作进度拖延感到焦虑。”(避免评价性语言)
感受:“这让我产生自我怀疑。”
需要:“我希望获得更清晰的优先级指导。”
请求:“下次任务分配时,能否提前与我同步目标?”
3. 创造深度联结的仪式感
微小行动:每天10分钟“无电子产品对话时间”,分享彼此的“今日三件感恩小事”。
体验式共鸣:共同参与一项挑战(如徒步、即兴戏剧),在不确定性中建立信任。
4. 与负面情绪和解
接纳练习:当感到悲伤时,默念:“此刻我有权利悲伤,这是正常的。”
重构叙事:将“我总是失败”改为“我从这次挫折中学到了______。”
五、情感的哲学启示
斯多葛学派:区分可控与不可控之事(如无法改变他人态度,但可调整自身回应方式)。
存在主义心理学:情感赋予生命意义——焦虑源于对自由的觉知,恰是创造价值的起点。
东方智慧:中国“中庸之道”强调情感节制(如儒家“喜怒不形于色”),日本茶道通过“一期一会”珍视瞬时情感。
六、给当代人的情感生存指南
设定情感边界:像管理财务一样规划时间与精力分配,避免过度卷入他人情绪漩涡。
培养“情绪耐受力”:接受不完美关系,理解冲突是亲密关系的必经阶段。
寻找情感共同体:加入读书会、艺术社群,通过创作(写作、绘画)外化内在体验。
结语
情感如河流,既有暗涌的漩涡,也有奔涌的欢歌。真正的“情感成熟”不在于永远快乐,而在于学会与情绪共舞——在脆弱中保持坚韧,在混沌中培育希望。你的每一次情感选择,都在书写属于自己的人生诗篇。
I don’t think the title of your article matches the content lol. Just kidding, mainly because I had some doubts after reading the article.
Thank you for your sharing. I am worried that I lack creative ideas. It is your article that makes me full of hope. Thank you. But, I have a question, can you help me?
Thanks for sharing. I read many of your blog posts, cool, your blog is very good.