In C++, where are static, dynamic and local variables stored? How about in C and Java?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you’re compiling C/C++ to create a windows executable (or maybe for any x86 system) then static and global variables are usually stored in a segment of the memory called a data segment. This memory is usually also divided to variables which are initialized and those that are not initialized by the program in their definition.
Local variables which are defined inside a functions are allocated on the running stack of the program, alongside the return address of the function.
By “dynamic” I’m assuming you mean things allocated using
newormalloc. These are usually stored in yet another area of memory called “the heap” (which has nothing to do with the “heap” data structure)All these details are highly platform dependent and usually, as a programmer you would not need to even be aware of them.