Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Given the partial program code below. Fill in the CONTENTS column of the memory

ID: 3705781 • Letter: G

Question

Given the partial program code below. Fill in the CONTENTS column of the memory map shown after the code. Assume that all variables require 4 bytes of memory (even though we know that double requires 8).

int number = 7;                   // Integer variable

int age = 30;                     // Integer variable

double pressure = 45.7;         // Float variable

double mass = 2.3489;            // Double variable

string name = "John";            // String variable

int *p_value = 0;                // Pointer to an integer

int *p_data = 0;                  // Pointer to another integer

double *p_one = 0;               // Pointer to a double type

double *p_two = 0;               // Pointer to a double type

string *p_name = 0;                     // Pointer to a string type

int j = 0, k = 0;                // For use in loops

int array_one[10] = {2, 4, 6, 8, 10, 12, 14, 16, 18, 20}; // An array

   // Initialize the pointers. NOTE: * is not used here.

   p_data = &age;

   p_value = &number;

   p_one = &pressure;

p_two = &mass;

p_name = &name;

Show the memory map at this point in the program.

ADDRESS

CONTENTS

VARIABLE

1200

age

1204

number

1208

pressure

1212

mass

1216

name

1220

1224

p_data

1228

p_value

1232

P_one

1236

P_two

1240

P_name

Following the code above assume that the following 6 statements are executed resulting in changes to the memory map.

       p_value = p_data;

       age = 17;

       number = 45;

       *p_two = *p_one;

       *p_one = 56.5;

       *p_name = "Jane";

Show the memory map at this point in the program following the changes made by the code above.

ADDRESS

CONTENTS

VARIABLE

1200

age

1204

number

1208

pressure

1212

mass

1216

name

1220

1224

p_data

1228

p_value

1232

P_one

1236

P_two

1240

P_name

ADDRESS

CONTENTS

VARIABLE

1200

age

1204

number

1208

pressure

1212

mass

1216

name

1220

1224

p_data

1228

p_value

1232

P_one

1236

P_two

1240

P_name

Explanation / Answer

Let's put this in table format:

&name

As per the table 1,

&age =1200

&number = 1204

&pressure = 1208

&mass = 1212

&name = 1216

Now our table becomes..

Table 1 is filled.

ADDRESS

CONTENTS

VARIABLE

1200

30

age

1204

7

number

1208

45.7

pressure

1212

2.3489

mass

1216

John

name

1220

1224

1200

p_data

1228

1204

p_value

1232

1208

P_one

1236

1212

P_two

1240

1216

P_name

After executing 6 statements:

p_value = p_data; => = p_data stores address of age, now p_value also stores the address of age

age = 17;

number = 45;

*p_two = *p_one; value at the address p_two is changed to value at the address p_one means...

p_two stores the address of mass

value at the address p_two is mass = 2.3489

p_one stores the address of pressure

value at the address p_one is pressure = 45.7

*p_two = *p_one; => mass = pressure = 45.7

*p_one = 56.5; => pressure = 56.5

*p_name = "Jane";

Our table..

Filling table 2.

ADDRESS

CONTENTS

VARIABLE

1200

17

age

1204

45

number

1208

56.5

pressure

1212

45.7

mass

1216

Jane

name

1220

1224

1200

p_data

1228

1200

p_value

1232

1208

P_one

1236

1212

P_two

1240

1216

P_name

Variable number age pressure mass name Its value 7 30 45.7 2.3489 John Its pointer p_value p_data p_one p_two p_name Pointer value &number &age &pressure &mass

&name

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote