For C++ Write a code fragment that allocates an array of double of size 10 using
ID: 3864057 • Letter: F
Question
For C++
Write a code fragment that allocates an array of double of size 10 using new and initializes a pointer. Include the declaration of the pointer. Write the statement that frees the memory allocated above
Also, I am reviewing the definition of a default assignment operator. for C++.
I am told that "It assigns each data member fr simple data types." does this mean that class defined objects do not work at all unles the = is overloaded? By simple data types does this mean already reconized types such as int floats and doubles?
Explanation / Answer
Write a code fragment that allocates an array of double of size 10 using new and
initializes a pointer. Include the declaration of the pointer.
Write the statement that frees the memory allocated above.
double *arrayPtr; //Declares an array pointer of doubles.
arrayPtr = new double[10]; //Allocates an array of 10 doubles to the pointer arrayPtr.
delete[] arrayPtr; //Frees the memory allocated above.
Also, I am reviewing the definition of a default assignment operator. for C++.
I am told that "It assigns each data member fr simple data types." does this mean that
class defined objects do not work at all unless the = is overloaded? By simple data types
does this mean already reconized types such as int floats and doubles?
No. Default assignment operators on a class doesn't work in the below cases:
1. The class either has a non-static type reference or const member.
2. The class is derived from a base class with inaccessible copy assignment operator.
In these cases, the programmer should define the assignment operator exclusively, unless
otherwise is not allowed to use it.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.