Gate CS-2017-1 Question Paper With Solutions

Q. 64 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) ; 
} 

 

(A) 23

(B) 24

(C) 26

(D) 27

Answer: (A)

Explanation:

Gate CS-2017-1 Question Paper With Solutions Gate CS-2017-1 Question Paper With Solutions

Learn More:   Gate CS-2008 Question Paper With Solutions

LEAVE A REPLY

Please enter your comment!
Please enter your name here