Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ 1. What is the delete keyword used for? To remove a pointer address from the stack To delete both the pointer and to deallocate

C++

1.
What is the delete keyword used for?
To remove a pointer address from the stack
To delete both the pointer and to deallocate the space in the heapthat is pointed to.
To deallocate the space in the heap pointed to by a pointer.
To delete the value stored in the heap pointed to by apointer
2.
Which of the following declarations is legal (will not generate anerror)?
int q = new *int;
int q = new int;
int q* = new int;
int *q;
3.
Which keyword can be used to allow a non-member function to see theprivate variables of another class?
protected
grant
friend
overload
4.
Consider the following main function:
int main()
{
Time t(2, 50);
t.setHour(5);
t.setMinute(20);
cout << "The time is " << t << endl;
}
What is necessary in the Time class to make this main functioncompile?
None of the above.
The Time class must have the data member t defined in the publicarea of the class.
The << operator must be overloaded for the Time class
A friend function called t is needed.
5.
In which of the following ways can you write an operator overload?(Select all that apply)
in a class member function
in a nonmember function
in the main function
in a friend function
6.
What is printed by these statements?
int p1 = 3;
int &p2 = p1;
p2 = p1;
cout << p1 << endl;
The address in the stack of p1
An error occurs
The address in the stack of both p1 and p2
3
7.
Suppose cursor is a pointer that points to a penguin node in alinked list using a penguin class that includes a member functionget_link(). You wish to move cursor to point to the next node (tothe next penguin) in the list. Which statement do you use?
cursor++;
cursor = cursor->get_link( );
cursor = get_link();
cursor.get_link();
8.
Suppose cursor points to a penguin node in a linked list using apenguin class, which includes functions called get_data() andget_link(). What Boolean expression should be true when thatpenguin node is the ONLY node in the list?
cursor->get_data( ) == 0.0
cursor->get_data( ) == NULL
cursor->get_link( ) == NULL
cursor == NULL
9.
The following steps have been performed for deleting a node from alinked list. The nodes have the member accessor functionget_link(). The head_ptr points to the head node of a list.
Step 1: Set up a local variable called remove_ptr and set it equalto head_ptr
Step 2: Set head_ptr equal to the head_ptr->get_link()
Step 3: Delete remove_ptr
Which of the following situations should use these steps?
To delete ALL nodes from a list
To delete a node from the front of a list
To delete a node from the end of a list
To delete a node from the middle (neither front nor end) of alist.
10.
Which operation is better for storing items in an array thanstoring items on a linked list?
retrieve a copy of the item at location i.
inserting an item at the beginning (position 0).
deleting an item at the beginning (position 0).
Growing the size of the container.
11.
You are working with a node class named node. Suppose that f is anon-member function with a prototype like this with a missing datatype in the parameter list:
void f(________ head_ptr);
// Precondition: head_ptr is a head pointer for a linkedlist.
// Postcondition: The function f has done some computationwith
// the linked list, but the list itself is unchanged.
What is the best data type for head_ptr in the parameter list ofthis function?
node* &
node*
node
node&

Step by Step Solution

3.45 Rating (145 Votes )

There are 3 Steps involved in it

Step: 1

Answer 1 To delete both the pointer and to deallocate the space in the heapthat is pointed to 2 int q 3 friend 4 The operator must be overloaded for the Time class 5 in a class member function in a no... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Project management

Authors: Harvey maylor

4th Edition

027370432X, 978-0273704324

More Books

Students also viewed these Electrical Engineering questions