Question 47

CSMCQ2 marksNeeds review
Consider the C function 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;
}
}
When foo is called with a pointer to the root node of the given binary tree, what will it print?
Diagram for Computer Science and Information Technology question 47

Your answerChoose one option.

Log in to check the answer

You can attempt this question now. Sign in to view the answer key, explanations and discussion.Log in to check answer

EXPLORE & PRACTISE

Paper and topic context

See where this question comes from and choose what to practise next.

2023CS

GATE CSE 2023 · Paper 1

Computer Science and Information Technology · Original paper archive

Section
Computer Science and Information Technology
Question type
Multiple choice (MCQ)
Marks
2 marks

Practise related topics

Explore more previous year questions using this question’s imported topic tags.

computer science

GATE CSE previous year questions

information technology

GATE CSE previous year questions

computing

GATE CSE previous year questions

programming data structures

GATE CSE previous year questions

Programming and Data Structures

GATE CSE previous year questions

Comments

Ask a question, share your approach, or help someone understand.

Log in to view the discussion

You’re not logged in. Log in or create an account to see discussions and add comments.