Gate2017 cs Q47

0. The output of executing the following C program is ____.
# include
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) ;
}

  • Option : B
  • Explanation : Count in the function total is static.
    iCountTable i
    502
    423(2+1)
    335(3+2)
    256(5+1)
    167(6+1)
      = 23
Cancel reply

Your email address will not be published. Required fields are marked *


Cancel reply

Your email address will not be published. Required fields are marked *