What value will be returned if the function call is func4 1

What value will be returned if the function call is func(!4) 1 2 3 None of above What does the function func do? Count number of digits in a decimal number Count the number of is in the binary representation of a decimal number Count the number of is in a decimal number None of above

Solution

Please follow the code and comments for description :

CODE :

#include <stdio.h> // header files

int func(int x) { // fucntion declaration
int count = 0;
while(x) { // iterate over the loop
count++; // increment
x = x & (x - 1); // check for the values
}
return count; // return the count
}

int main(void) { / driver method
  
   int c = func(14); // call the function
   printf(\"%d\", c); // print the data
   return 0;
}

a) When this function is called this prints the value 3 as when compared with the value over the binary \'and\' operator this do satify for the first three loop and thus rejects over the fourth loop making the 3 as the value to be returned as the count.

So the answer is OPTION C (3).

b) The function func does the count of the number of ones ove the integre passed with the conversion to the binary format. So the answer is OPTION D (Count the number of 1\'s in the binary representation of a decimal number).


Hope this is helpful.

 What value will be returned if the function call is func(!4) 1 2 3 None of above What does the function func do? Count number of digits in a decimal number Cou

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site