Question: Edit the explore.c file to add printf statements to print both variable values and values of the pointers to variables and/or array[0] where indicated. Note

Edit the explore.c file to add printf statements to print both variable values and values of the pointers to variables and/or array[0] where indicated. Note that if you print a pointer value you should use %p as the format. For all other values, you should use %x format. Remember to build your program using the m32 option for a 32-bit application.You should find that as automatic variables are allocated memory or as arguments are pushed onto the stack to be passed to a function (foobar) that the addresses of the locations in memory are decreasing.

In the main program printf loop for array[i], it should be sufficient to print for i = 0 to i < 6. Can you find the locations that have been assigned for the automatic variables and can you see their values?

In the foobar function printf loop for array[i], it should be sufficient to print for i = 0 to i < about 40 or 50. A sample output is provided in here. Can you find the locations that have been assigned for the automatic variable and the argument list variables? Can you see the same data that you printed above in the main program further back on the stack?

this is explore.c

/* explore.c: program to explore memory locations via pointers bob wilson 03/13/2003 modified by Ron Cheung 7/8/2003 */ #include  int a = 0x13579753; static int b = 0x24680864; void foobar(int, int, int *, int *); int main(void) { static int c = 0xaaaa5555; int d = 0x5555aaaa; int *ap = &a; int *bp = &b; int *cp = &c; int *dp = &d; int array[1] = {0x01010101}; /* add code here to print the address of array[0] */ /* add code here to print the variables a, b, c, d and pointers */ /* add code here to print array[i] for i = 0 to high enough value */ /* call subroutine foobar and pass arguments */ foobar(a, d, &a, &d); return; } void foobar(int x, int y, int *xp, int *yp) { int array[1] = {0x10101010}; printf("Entering foobar "); /* add code here to print address of array[0] */ /* add code here to print array[i] for i = 0 to high enough value */ return; } 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock 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 Databases Questions!