Consider each of the following questions carefully. You are required to give the
ID: 3850823 • Letter: C
Question
Consider each of the following questions carefully. You are required to give the answer true or false and justify your answer. If it is true, explain why it is true. i. Structs are the same as classes, except that their access control is, by default, private. ii. You should use delete [] to return the space allocated to any object to the freestore. iv. The virtual keyword must be used for all inherited functions. (b) Write a loop that will search an array of int values, myArray, to determine if it contains the integer value stored in a variable myInt and display the message "Found" if it finds it. Clearly comment your code. You may assume the myArray and myInt are both declared and initialised.Explanation / Answer
Hi.
Please find below the answer-
Ans a) i) true. Structures are functionally same as the classes but only difference is that their members are private by default. Both structures and classes have data members and member functions that can be used to map any real world entity.
Ans a) ii) true. delete[] is one of the operators in C++ that is used to de-allocate the memory used by a variable at the time of dynamic memory allocation. If we have created a pointer of class object type and we are done with the processing of that object, then we need to delete the memory allocated for the set of objects.
Example -
Ans a) iv) False. A virtual member is a member function that can be redefined in a derived class, while preserving its calling properties through references.
Ans b) Below is the code-
for(int i=0;i<n;i++)
{
if(myArray[i]==myInt) {
cout<<"Found";
}
else
{
cout <<"Not Found";
}
}
Thanks and Regards,
Vinay Singh
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.