GATE CS 2020 (Forenoon) — Question 58

Programming in CFunctions, Parameter Passing, Scope Rules, RecursionNAT2 marksHard

Consider the following C functions:
c
1int tob(int b, int* arr) {
2    int i;
3    for(i=0; b>0; i++) {
4        if(b%2) arr[i]=1;
5        else arr[i]=0;
6        b=b/2;
7    }
8    return(i);
9}
10int pp(int a, int b) {
11    int arr[20];
12    int i, tot=1, ex, len;
13    ex=a;
14    len=tob(b,arr);
15    for(i=0; i<len; i++) {
16        if(arr[i]==1)
17            tot=tot * ex;
18        ex = ex * ex;
19    }
20    return(tot);
21}
22
The value returned by pp(3,4) is ________.
Practise the full 2020-FN paper
Challenge a friend: WhatsApp Telegram
From RENYXERAThis week's 10-question challengeSame 10 past-GATE questions for everyone this week — see where you stand.
Practise more on Functions, Parameter Passing, Scope Rules, RecursionTimed, in the real exam interface · free to start

A GATE question every morning

One real past-paper question every morning for your branch, answer hidden until you tap. Free on Telegram.

Join
Stuck? Ask in the student group