GATE CS 2017 (Forenoon) — Question 55

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

The output of executing the following C program is ________.
c
1#include <stdio.h>
2int total (int v) {
3    static int count = 0;
4    while (v) {
5        count += v & 1;
6        v >>= 1;
7    }
8    return count;
9}
10void main ( ) {
11    static int x = 0;
12    int i = 5;
13    for (; i > 0; i--) {
14        x = x + total (i);
15    }
16    printf ("%d\n", x);
17}
18
Practise the full 2017-FN paper
Challenge a friend: WhatsApp Telegram
From RENYXERAPractise this subject in the exam simulatorTimed, GATE-style tests with analytics that find your weak topics.
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