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

Use the following declarations for all parts of this question: struct date { int

ID: 643316 • Letter: U

Question

Use the following declarations for all parts of this question:

    struct date {

           int day, month, year; };

    date *today;

    int *p;

   

    1) Create a dynamic integer variable using pointer p and a dynamic structure variable  

        using pointer today.

    int * p = new int;

   

    2) Assign 10 to the dynamic integer variable and May 21, 1986 to the dynamic structure

* day = 10;

        variable.

   3) Release memory for the dynamic integer variable and create a dynamic integer array

        of size 50 using pointer p.

    4) Release memory for the dynamic structure variable and the dynamic array, and clear

        the contents of pointer p and today.

Explanation / Answer

Use the following declarations for all parts of this question:
struct date {
int day, month, year;
};
date *today;
int *p;
1) Create a dynamic integer variable using pointer p and a dynamic structure variable using pointer today.
int * p = new int;
today = new date;

2) Assign 10 to the dynamic integer variable and May 21, 1986 to the dynamic structure
*p = 10;
today->day = 21;
today->month = 5;
today->year = 1986;

3) Release memory for the dynamic integer variable and create a dynamic integer array of size 50 using pointer p.
delete p;
p = new int[50];

4) Release memory for the dynamic structure variable and the dynamic array, and clear the contents of pointer p and today.
delete today;
delete[] p;
p = NULL;
today = NULL;

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