Question: Study the following program and answer the questions: #include #include int uig; int ig = 5; int func() { return 0; } int main()

Study the following program and answer the questions: #include #include int uig;

 

Study the following program and answer the questions: #include #include int uig; int ig = 5; int func() { return 0; } int main() } int local; int *ptr; ptr (int *)malloc(sizeof(int)); = printf("An address from BSS: %p ", &uig); printf("An address from Data segment: %p ", &ig); printf("An address from Code segment: %p ", &func); printf("An address from Stack segment: %p ", &local); printf("An address from Heap: %p ", ptr); printf("Another address from Stack: %p ", &ptr); free(ptr); return 0; Questions: Examine last line of output. It shows another address from stack. 1. Why &ptr is in the stack segment? 2. Why distance is 4 byte between local and &ptr? 3. Why &ptr is less than &local?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Solution 1 Why ptr is in the stack segment Ptr is a stack var... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!