0 votes 0 votes what is the value of z? #include <stdio.h> int main() { int a[]={3,5,6,4}; int z=0; for (int y=0;y<(sizeof(a)/sizeof int);y++) z=a[y]+value(a[y]); } int value(int *x) { static int count; while(*x) { count=count+*x&1; *x>>1 ; } } ck asked Aug 24, 2018 edited Aug 24, 2018 by ck ck 486 views answer comment Share Follow See all 6 Comments See all 6 6 Comments reply Show 3 previous comments MiNiPanda commented Aug 24, 2018 reply Follow Share int value(int *x) x is a pointer variable that can hold the address of an integer. value(a[y]) means you are passing an integer value and not it's address. For the prog to run properly we should pass the address of a[y]. Also there is not return statement in the function but the return type is of int. I guess it should be return count .. :/ 0 votes 0 votes srestha commented Aug 24, 2018 reply Follow Share though print statement not given but function value() will count number of 1's in each element of the array 0 votes 0 votes newdreamz a1-z0 commented Sep 5, 2018 reply Follow Share count=((count+(*x))&1) is this is the right way to resolve the precedence? if not then which order should i follow. 0 votes 0 votes Please log in or register to add a comment.
Best answer 0 votes 0 votes I think the answer is 11 as the count variables count the number of 1 in the binary representation of array elements. sandygate answered Aug 24, 2018 selected Sep 5, 2018 by ck sandygate comment Share Follow See all 2 Comments See all 2 2 Comments reply Rishav Kumar Singh commented Aug 25, 2018 reply Follow Share If you are not confirm then post it as comment not as answer, please. 2 votes 2 votes Abbas commented Sep 6, 2018 reply Follow Share @sandygate: can you explain?? 0 votes 0 votes Please log in or register to add a comment.