Consider the C function foo and the binary tree shown:
When foo is called with a pointer to the root node of the given binary tree, what will it print?
c

- A3 8 5 13 11 10
- B3 5 8 10 11 13
- C3 8 16 13 24 50
- D3 16 8 50 24 13
Programming in CFunctions, Parameter Passing, Scope Rules, RecursionMCQ2 marks · −2/3 if wrongMedium
1typedef struct node {
2 int val;
3 struct node *left, *right;
4} node;
5int foo(node *p) {
6 int retval;
7 if (p == NULL)
8 return 0;
9 else {
10 retval = p->val + foo(p->left) + foo(p->right);
11 printf("%d ", retval);
12 return retval;
13 }
14}
15
A GATE question every morning
One real past-paper question every morning for your branch, answer hidden until you tap. Free on Telegram.