Answered step by step
Verified Expert Solution
Question
1 Approved Answer
ASIDE: EVERY ADDRESS YOU SEE IS VIRTUAL Ever write a C program that prints out a pointer? The value you see (some large number, often
ASIDE: EVERY ADDRESS YOU SEE IS VIRTUAL Ever write a C program that prints out a pointer? The value you see (some large number, often printed in hexadecimal), is a virtual address. Ever wonder where the code of your program is found? You can print that out too, and yes, if you can print it, it also is a virtual address. In fact, any address you can see as a programmer of a user-level program is a virtual address. It's only the OS, through its tricky techniques of virtualizing memory, that knows where in the physical memory of the machine these instructions and data values lie. So never forget: if you print out an address in a program, it's a virtual one, an illusion of how things are laid out in memory; only the OS (and the hardware) knows the real truth. Here's a little program (va.c) that prints out the locations of the main() routine (where code lives), the value of a heap-allocated value returned from malloc(), and the location of an integer on the stack: #include #include int main(int argc, char *argv[]) { printf("location of code : %p ", main); printf("location of heap : %p ", malloc (10016)); int x = 3; printf("location of stack: %p ", &X); return x; } When run on a 64-bit Mac, we get the following output: location of code : 0x1095afe50 location of heap : 0x109600800 location of stack: 0x7fff691aea 64 From this, you can see that code comes first in the address space, then the heap, and the stack is all the way at the other end of this large virtual space. All of these addresses are virtual, and will be translated by the OS and hardware in order to fetch values from their true physical locations. Explain : - how the int x=3 declaration allows the program to find the location of the stack
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started