Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question 1: Pointers You are given the following C code and memory diagram. The contents column of the memory diagram shows the value of the

Question 1: Pointers

  1. You are given the following C code and memory diagram. The contents column of the memory diagram shows the value of the variable. Update the contents column of the memory diagram for each assignment in main().

long *pt; long data; long buffer[4]; void main(void){ pt = &buffer[1]; *pt = 1234; data = *pt; }

address contents variable 0x20000000 0x00000000 pt 0x20000004 0x00000000 data 0x20000008 0x00000000 buffer[0] 0x2000000C 0x00000000 buffer[1] 0x20000010 0x00000000 buffer[2] 0x20000014 0x00000000 buffer[3]

  1. Consider the following code.

The function GetFifo returns two parameters. The return parameter is a boolean specifying whether or not the request was successful, and the actual data removed from the queue is returned via the call-by-reference parameter. The calling program InChar passes the address of its local variable data. Normally GetFifo does not have the scope to access local variables of InChar, but in this case InChar explicitly granted that right by passing a pointer to GetFifo.

#define FifoSize 10 /* Number of 8-bit data in FIFO */ unsigned char PutI; /* Index of where to put next */ unsigned char GetI; /* Index of where to get next */ unsigned char Size; /* Number currently in the FIFO */ char Fifo[FifoSize]; /* FIFO data */

int GetFifo (char *datapt) { if(Size == 0 ) return(0); /* empty if Size=0 */ else{ *datapt=Fifo[GetI++];

Size--; if (GetI == FifoSize) GetI = 0; return(-1); } }

char InChar(void){

char data=0; if(GetFifo(&data)){}; return (data);

}

Questions:

  1. Sketch a simple diagram that illustrates the different scope of variables in the code. Use any notation you want to show global versus local variables and pointer variables. You are not given information about actual memory addresses, so do not try to set up a memory diagram.

  1. What would happen if GetFifo is called instead with the following parameter GetFifo(data)? Will rate thanks!!

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

Database Concepts

Authors: David M. Kroenke, David J. Auer

7th edition

133544621, 133544626, 0-13-354462-1, 978-0133544626

More Books

Students also viewed these Databases questions

Question

What is memory?

Answered: 1 week ago

Question

=+5. How does a synopsis differ from an executive summary? [LO-5]

Answered: 1 week ago