1 1 vote Consider storage class of a variable declared as static. Where the memory will be allocated? (A) Code Segment (B) Stack Segment (C) Heap Segment (D) Data Segment Data Structures + – srestha 2.1k views answer comment Share Follow Print See all 5 Comments 5 5 Comments reply vijaycs commented Jan 13, 2017 reply Follow flag data segment. https://en.wikipedia.org/wiki/Static_variable 2 2 replyShare Kapil commented Jan 13, 2017 reply Follow flag If it is uninitialized, then BSS segment or uninitialized data segment . If initialized, then initialized data segment. 3 3 replyShare srestha commented Jan 13, 2017 reply Follow flag thanks :) 1 1 replyShare srestha commented Jan 13, 2017 reply Follow flag @Kapil Can u elaborate more initialized and uninitialized portion? plz 0 0 replyShare vijaycs commented Jan 13, 2017 reply Follow flag ^ int static i; // default value of i=0. int static i=10. // initialized explicitely with value 10. https://en.wikipedia.org/wiki/.bss#BSS_in_C 2 2 replyShare Please log in or register to add a comment.
Best answer 2 2 votes Code segment or text segment: Code segment contains the code executable or code binary. • Data segment: Data segment is sub divided into two parts – Initialized data segment: All the global, static and constant data are stored in the data segment. – Uninitialized data segment: All the uninitialized data are stored in BSS. Heap: When program allocate memory at runtime using calloc and malloc function, then memory gets allocated in heap. when some more memory need to be allocated using calloc and malloc function, heap grows upward as shown in above diagram. • Stack: Stack is used to store your local variables and is used for passing arguments to the functions along with the return address of the instruction which is to be executed after the function call is over. When a new stack frame needs to be added (as a result of a newly called function), the stack grows downward. saurabh rai answered Jan 13, 2017 • selected Jan 13, 2017 by srestha saurabh rai comment Share Follow 0 reply Please log in or register to add a comment.
3 3 votes All variables that are defined inside a function are normally created on the stack each time the function is called. These variables die as soon as control goes back from the function. However if the variables inside the function are defined as static then they do not get created on the stack. Instead they are created in a place in memory called "Data Segment". Such variables die only when progran execution comes to an end. nandini gupta answered Jan 13, 2017 nandini gupta comment Share Follow 0 reply Please log in or register to add a comment.