Kya BSS disk space leta hai? Nahi (sirf ek size record hota hai).
Heap kis direction mein barhta hai? Upar (higher addresses).
Stack kis direction mein barhta hai? Neeche (lower addresses).
malloc ka block kahaan rehta hai? Heap.
Ek function ka local int kahaan rehta hai? Stack.
Recall Feynman: ek 12-saal ke bacche ko explain karo
Socho tumhare program ko ek bada bookshelf milta hai. Sabse neeche wali shelf mein instruction manual hota hai — tum padh sakte ho lekin uspar kuch likh nahi sakte (Text). Agle shelves mein pehle se bhari hui toys hoti hain (Data) aur "zeros se bharo" label wale khaali boxes (BSS) — khaali boxes ko shifting truck mein pack karne ki zaroorat nahi, tum bas ek sticky note par "10 khaali boxes" likh dete ho. Beech ke bade space mein, toy pile neeche se upar barhta hai jab bhi tum naya toy maangte ho (Heap = malloc), aur plates ka stack chhat se neeche barhta hai jab bhi tum naya kaam shuru karte ho aur ek plate rakhte ho (Stack = function calls). Jab kaam khatam ho, plate automatically wapas chali jaati hai. Agar toy pile aur plate stack kabhi aapas mein takra jaayein — room khatam!
Buffer overflow and stack smashing — stack ki security side.
Which segment stores compiled machine instructions and is read-only?
Text (code) segment.
Where do initialized non-zero global/static variables live?
Data segment mein.
Where do uninitialized or zero-initialized globals/statics live?
BSS segment mein.
Why does BSS take no space in the executable file?
Yeh sirf ek reserve karne wala size store karta hai; OS ise load time par zero-fill karta hai, isliye all-zero contents disk par save nahi karne padte.
What is the default value of an uninitialized GLOBAL variable in C?
Zero (BSS mein jaata hai, zero-initialize hona guaranteed hai).
What is the value of an uninitialized LOCAL (auto) variable?
Indeterminate/garbage — stack par hota hai aur auto-zeroed nahi hota.
Which direction does the heap grow?
Higher addresses ki taraf (program break upar jaata hai brk/sbrk se).
Which direction does the stack grow?
Lower addresses ki taraf (stack pointer push par decrease hota hai).
When you call malloc inside a function, where is the returned block, and where is the pointer?
Block heap par hota hai; pointer variable stack par hota hai.
What tracks the top of the heap?
Program break, brk/sbrk se adjust hota hai.
What tracks the top of the stack?
Stack pointer register (jaise rsp).
What causes a stack overflow vs heap exhaustion?
Stack overflow = bahut gehri recursion/bade locals (SP limit se aage); heap exhaustion = malloc NULL return karta hai.