Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Existing Code: Existing Code: Make sure your compile with -lreadline #include #include char * pressKey(char *msg) { char *dummy=readline(msg); return dummy; } int main(int argc,

image text in transcribedExisting Code:

Existing Code:

Make sure your compile with -lreadline
#include  #include  char * pressKey(char *msg) { char *dummy=readline(msg); return dummy; } int main(int argc, char * argv[],char * envp[]) { int i; short numbers[]={0,1,2,3,4,5}; pressKey("Press return to see the addresses and contents of numbers: numbers[i]: "); fprintf(stdout," The base address of numbers is: %p ",numbers); for(i=0;i  Part III: Address Arithmetic (8 marks) Testing out of bound values Modify the example addressArithmetic3.c by creating an array of 5 values before numbers and a second array after numbers. Fill each with distinct values. Use #include to include the declaration of your datatype from Part I. (1 mark each except for g which is 2 marks) a. Display values from numbers using subscripts from 6 to 9. From which array (if either) do these values come from? b. Display values from numbers using subscripts from -1 to -5. From which array (if either) do these values come from? c. Modify your listing so that instead of using numbers[i] you use the pointer dereferencing notation *(numbers+i) to refer to elements of the array. Is there any change in output? d. Add the following declarations to your code after the 3 arrays: char *newStringl=(char * )alloca(100); char newString2[100]; struct yourDataType *iteml=(struct yourDataType *) calloc(sizeof (struct yourDataType),5); Print out the value of the pointers newStringl and new String2 Where in memory are they in relation to your arrays? Are they in the stack or the heap? e. Add values from -3 to +3 to both newStringl and newString2 and print out the values. Explain the results in terms of address arithmetic. f. Print out the values iteml and &iteml. Where are they in memory in relationship to your arrays? Explain the results in terms of address arithmetic? 8. Set up your program so that it uses both the function and the script mtrace to trace memory allocation. Describe what you did. What does the mtrace shell command tell you about the allocation and freeing of memory in the program? (2 marks)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Automating Access Databases With Macros

Authors: Fish Davis

1st Edition

1797816349, 978-1797816340

More Books

Students also viewed these Databases questions

Question

what are the provisions in the absence of Partnership Deed?

Answered: 1 week ago

Question

1. What is called precipitation?

Answered: 1 week ago

Question

1.what is dew ?

Answered: 1 week ago

Question

1.The difference between climate and weather?

Answered: 1 week ago

Question

2. Identify issues/causes for the apparent conflict.

Answered: 1 week ago

Question

3. What strategies might you use?

Answered: 1 week ago