1,249 views
0 votes
0 votes
Folks, as the global or static variables are stored in data section of process and their scope is throughout the program, but once the main() function returns or complete execution or when whole program is executed and activation record of main() is also popped off from stack, but then what happens to that data section?

Does global variable stays or the whole process is deleted including global variables from memory once the program ran to completion?

1 Answer

2 votes
2 votes
Look it's not data section but data segment first thing. Undoubtedly Global Variables, Static variables r present in there when d execution is taking place. The program is loaded from Hard Disk into RAM for execution. So d values r not retained after d program has finished execution. And when d process ends it is no longer process but Program. The executable of d prog supported by Windows or d .exe (for process) is format. This u might be aware of. Once whole process ends not program d values r no longer retained. D program goes back to d location of Hard Disk. I Hope this helps u. :). The values cud be retained if File Handling is used. :)

Related questions

1 votes
1 votes
2 answers
1
radha gogia asked Aug 9, 2015
1,926 views
If I write #include<stdio.h int a; main() { //code }then since a is a global variable so what is the storage class of it , is it extern ?
1 votes
1 votes
2 answers
4