Operating-Systems
December 8, 2023
Question 8139 – Programming
December 8, 2023
Operating-Systems
December 8, 2023
Question 8139 – Programming
December 8, 2023

Question 7951 – Programming

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(; 1> 0; i--)    {
                  x = x + total(i);
               }
               printf("%d\n", x);
           }

Correct Answer: A

Question 14 Explanation: 
Arithmetic operators have least priority in this case, as count+=v & 1, we first compute v& 1 and then adds to count variable.

A
23
B
24
C
25
D
26

Leave a Reply

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