Q. Consider the following code snippet
function tail(o)
{
for (; o.next; o = o.next) ;
return o;
}
Will the above code snippet work? If not, what will be the error?
function tail(o)
{
for (; o.next; o = o.next) ;
return o;
}
Will the above code snippet work? If not, what will be the error?
β
Correct Answer: (C)
Yes, this will work
Explanation: The above code uses a for loop to traverse a linked list data structure and return the last object in the list. This will perfectly work.