212k views
5 votes
Suppose that f is a function with a prototype like this:

void f(________ head_ptr);
// Precondition: head_ptr is a head pointer for a linked list.
// Postcondition: The function f has done some computation with
// the linked list, but the list itself is unchanged.
What is the best data type for head_ptr in this function?
A. node
B. const node
C. node*
D. const node*

1 Answer

7 votes

Answer:

C. node*.

Step-by-step explanation:

A linked list is a linear data structure where which contains elements stored at non contiguous memory location.They are linked to each other.Every node in a linked list is a pointer.Node consists of a data element and a pointer of node type which contains the address of the next node.

So to connect all the nodes we need the node to be a pointer.That's how we can connect them by address.

User Ganesh D
by
6.7k points