QuestionQuestion

1. Fill in the boxes below with the final contents of each corresponding variable. The number to the left of the box is the memory address at which the variable resides, and the letter below is the name of the variable.

a.
int a, b, *c;
a = 6;
b = 12;
c = &b;
a = a + *c;

a 0x20
b 0x24
c 0x28

b.
int a, *b, *c;
a = 2;
c = &a;
b = c;
*c = a + *b;

a 0x20
b 0x24
c 0x28

c.
int a[4] = {2, 4, 6, 8 };
int b, c, *d;
d = a;
b = *(a + 1);
c = *d + 1;
a
0x20
0x24
0x28
0x2C

b 0x30
c 0x34
d 0x38

2. For the following problems, declare a pointer, using the new operator allocate the specified memory, and then de-allocate it using the delete operator.
a. Dynamic array of integers of size 5.
b. Dynamic array of characters of size 12.
c. Dynamic array of Car structures of size 4.
d. Dynamic array of Strings of size 3.

3. Below write a piece of code which would cause a memory leak.

4. Write a function named generateDoubleArray which accepts a size as the parameter and returns back a dynamic array of doubles with size number of elements. Initialize each element in the array to 0.0 prior to returning the array. Give an example of a function call to generateDoubleArray.

Solution PreviewSolution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

C++ Programming Problems
    $23.00 for this solution

    PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

    Find A Tutor

    View available Visual Basic Programming Tutors

    Get College Homework Help.

    Are you sure you don't want to upload any files?

    Fast tutor response requires as much info as possible.

    Decision:
    Upload a file
    Continue without uploading

    SUBMIT YOUR HOMEWORK
    We couldn't find that subject.
    Please select the best match from the list below.

    We'll send you an email right away. If it's not in your inbox, check your spam folder.

    • 1
    • 2
    • 3
    Live Chats