what is the purpose of the code, and is there any problem
with it.
bool f( uint n )
{ return (n & (n-1)) == 0; }
function returns if the number is a power of 2. if number value is 1, 2, 4, 8, 16 ... then TRUE is returned.
f(1) => 1 & 0 => 0001 & 0000 => 0
f(2) => 2 & 1 => 0010 & 0001 => 0
f(3) => 3 & 2 => 0011 & 0010 => 1 (non zero) => return true
f(4) => 4 & 3 => 0100 & 0011 => 0
f(5) => 5 & 4 => 0101 & 0100 => 4 (non zero) => return true
f(6) => 6 & 5 => 0110 & 0101 => 4 (non zero) => return true
f(7) => 7 & 6 => 0111 & 0110 => 6 (non zero) => return true
f(8) => 8 & 7 => 1000 & 0111 => 0
| Is This Answer Correct ? | 1 Yes | 0 No |
main() { int *ptr=(int*)malloc(sizeof(int)); *ptr=4; printf("%d",(*ptr)+++*ptr++); }
5 Answers Vector, Vector Solutions,
can u write a program in C, which does not use = (eqaul)or any arithmatic assignment(like -=,+=,*= etc) operator to swap to number?
a=0; while(a<5) printf("%d\n",a++); how many times does the loop occurs? a.infinite b.5 c.4 d.6
What is the role of && operator in a program code?
Explain what is the most efficient way to store flag values?
What are dynamically linked and statically linked libraries?
Write a program to write a given string in maximum possibilities? i.e str[5]="reddy"; i.e we can write this string in 120 ways for that write a program
How do I declare a pointer to an array?
Explain what are binary trees?
which type of aspect you want from the student.
Explain what is wrong in this statement?
What is a constant?