The output of executing the following C program is _______________ .…

GATE · 2017 · CS · Set 1 · Computer Science & IT

The output of executing the following C program is _______________ .

#include<stdio.h>
int total(int v) {
static int count = 0;
while(v) {
count += v&1;
v >>= 1;
}
return count;
}
void main() {
static int x=0;
int i=5;
for(; i>0; i--) {
x = x + total(i);
}
printf("%d\n", x);
}

Attempted by 139 students.

Sign up free to check your answer

Sign up free

Explore the full course: Gate Guidance By Sanchit Sir

Loading lesson…