Give a oneline C expression to test whether a number is a
power of 2?
Answers were Sorted based on User's Feedback
Answer / dan
if (x & (x-1)) // false only if x is a power of 2
Is This Answer Correct ? | 102 Yes | 8 No |
Answer / ashutosh
I think
if (x & (x-1)) wont work when number is negative.
Is This Answer Correct ? | 12 Yes | 10 No |
Answer / fjords
if (int(log(x)) == log(x)) // log is to the base 2
Is This Answer Correct ? | 1 Yes | 0 No |
Answer / rahul priyadarshi
#define ISPOW2(x) ((x==1)?1:(x&(x-1)))?0:1
Is This Answer Correct ? | 1 Yes | 0 No |
Answer / yevgen
if ((num XOR (num - 1)) == num + num - 1) return true;
else return false;
Is This Answer Correct ? | 1 Yes | 0 No |
what is the output of following program ? void main() { int i=5; printf("%d %d %d %d %d ",i++,i--,++i,--i,i); }
#define int char main() { int i=65; printf("sizeof(i)=%d",sizeof(i)); }
write a c program to input initial & final time in the format hh:mm and find the time intervel between them? Ex inputs are initial 06:30 final 00:05 and 23:22 final 22.30
How do I write a program to print proper subset of given string . Eg :input: abc output:{},{a},{b},{c},{a,b},{a,c},{b,c}, {a,b,c}.I desperately need this program please mail me to saravana6m@gmail.com
struct point { int x; int y; }; struct point origin,*pp; main() { pp=&origin; printf("origin is(%d%d)\n",(*pp).x,(*pp).y); printf("origin is (%d%d)\n",pp->x,pp->y); }
1) int i=5; j=i++ + i++ + i++; printf("%d",j);This code gives the answer 15.But if we replace the value of the j then anser is different?why? 2)int i=5; printf("%d",i++ + i++ + i++); this givs 18.
main() { int i=5; printf("%d",++i++); }
write the function. if all the character in string B appear in string A, return true, otherwise return false.
Write a single line c expression to delete a,b,c from aabbcc
How to reverse a String without using C functions ?
33 Answers Matrix, TCS, Wipro,
main() { show(); } void show() { printf("I'm the greatest"); }
1. const char *a; 2. char* const a; 3. char const *a; -Differentiate the above declarations.