GATEverse Practice, past papers & mock tests
GATE 2023 · CS - Forenoon
Programming & Data StructuresTreesmediumMCQ2 marks
Consider the C function foo and the binary tree shown.
c
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;
    }
}
When foo is called with a pointer to the root node of the given binary tree, what will it print?
Save your progress

Related Programming & Data Structures PYQs