250 views
3 votes
3 votes
void fun(struct node* start)
{
    if(start == NULL)
        return;
    if(start->next != NULL )
        fun(start->next->next);
    printf("%d ", start->data);
}

The sum of the values printed by the above function when passed with the head to the following linked list is _____
$$1\to2\to 3\to 4\to 5\to 6\to 7$$

 

2 Answers

Best answer
3 votes
3 votes
The fun function is going to the last node of the list skipping every second value. (It will cause a runtime error if there are even number of elements in the list but will run fine if there are odd number of elements). The final value here is $7$ and it'll be printed. Then the recursion returns and $5,3,1$ will be printed.

$7 + 5 + 3+ 1=16.$
selected by
Answer:

Related questions

1 votes
1 votes
1 answer
4
gatecse asked Aug 9, 2020
185 views
What is the value of the postfix expression $8 \ 7 \ 2 \ 4 \ + \ – \ *?$: