0 votes 0 votes Consider the C function func shown below: int func(int num) { int count = 0; while (num) { count++; num>>= 1; } return (count); } The value returned by func(0235) is ________ Programming in C programming-in-c identify-function + – Purple asked Jan 23, 2016 edited Nov 29, 2023 by Hira Thakur Purple 820 views answer comment Share Follow See all 0 reply Please log in or register to add a comment.
Best answer 5 votes 5 votes In C language an integer constant starting with a 0 is treated as octal. So, $0235 = 157$ in decimal. Now, the code is giving the position of the most significant bit in the binary representation of the number. $157 = (10011101)_2$, so, MSB is at position 8. Arjun answered Jan 23, 2016 selected Jan 23, 2016 by Purple Arjun comment Share Follow See all 0 reply Please log in or register to add a comment.
0 votes 0 votes 8 Binary of 235:11101011 Now doing right shift and incrmenting by 1, means essentially counting the number of bits in the binary version of 235, which is 8. So ans is 8 chat28 answered Jan 23, 2016 chat28 comment Share Follow See all 7 Comments See all 7 7 Comments reply Purple commented Jan 23, 2016 reply Follow Share So no matter how many number of 0's is present before it? 0 votes 0 votes chat28 commented Jan 23, 2016 reply Follow Share Before what? The number is already given , find binary and count number of bits.That's it! That is exactly what the program is doing. 0 votes 0 votes Purple commented Jan 23, 2016 reply Follow Share i mean before any number. like for 0235 it is 11101011 and not 011101011. what if the number inside func() is 0. ie func(0) 0 votes 0 votes chat28 commented Jan 23, 2016 reply Follow Share 0 before a decimal number doesn't mean anything. 0 votes 0 votes Arjun commented Jan 23, 2016 reply Follow Share It does mean in C language. It is for octal numbers. 2 votes 2 votes cse23 commented Jun 3, 2016 reply Follow Share 0 for octal and 0x for hexadecimal like that? 0 votes 0 votes Arjun commented Jun 3, 2016 reply Follow Share yes.. And '0b' for binary but binary constant is not in C standard (only for GNU C). 2 votes 2 votes Please log in or register to add a comment.