Homework: Pointers

  < Previous  Next >

Write your answers to the following questions in a flat text file hwkPointers.txt (not a Word document nor a Rich Text Format file):
  1. Pointer Syntax:
    1. Write the declaration of a double pointer named average
    2. Write the declaration of a double pointer named aver and assign nullptr to it
    3. What is the difference between a. and b.?
    4. Dynamically allocate memory for a DNA object and store its address in a variable named dnaPtr
    5. Declare a one-dimensional array of 7 doubles (on the stack) named rainfall
    6. Declare and allocate memory (on the heap) for a one-dimensional array of 1024 doubles named prices
    7. Declare a two-dimensional array of doubles (on the stack) named tickerValues with 12 rows and 31 columns
    8. Declare and allocate memory (on the heap) for a two-dimensional array of strings named carMakes with 6 rows, each with 20 columns
    9. Give the declaration for a function assignPicture() that takes a pointer to a HugeStudentRecord object
    10. Give the declaration for a function calculateAverage() that takes an array of doubles and an int named count
    11. Write a call to calculateAverage(), passing it rainfall
  2. Write the implementation for doubleAmount() so that all of the following code executes and prints out just 14:
    int num = 7;
    doubleAmount( &num);
    std::cout << num;  
    
  3. Using just two words, describe what is wrong with the following code:
    CoolObject* p = new CoolObject;
    p->printInfo();
    p = new CoolObject;
    p->printInfo(); 
  4. For the three variable declarations below, for each one state if their contents are on the stack, on the heap or both?
    1. int counter = 0;
    2. string errorMsg = "";
    3. string* result = new string();

Submission

Submit your txt file at https://3110.cs.mtsu.edu/. For further instructions, please see the Miscellaneous page.

Rubric:

Points          Item
----------      --------------------------------------------------------------
_____ / 11      1
_____ /  3      2
_____ /  1      3
_____ /  1      4
        
_____ / 16      Total
      

Last Modified: