Skip to content

Beta · Data may be lost.Your data may be reset or lost.

GateBrew
← GATE CSE 2023
Questions

Q37

MCQ2 marks, −0.67Data structures

Consider the C\text{C} function foo\text{foo} and the binary tree shown.

typedef struct node {
    int val;
    struct node *left, *right;
} node;
int foo(node *p) {
    int retval;
    if (p == NULL)
        return 0;
    else {
        retval = p->val + foo(p->left) + foo(p->right);
        printf("%d ", retval);
        return retval;
    }
}

Figure 1

When foo\textsf{foo} is called with a pointer to the root node of the given binary tree, what will it print?

Sign in to save attempts.

The solution is hidden while you attempt this question. It opens once you check or show the answer.